Here's the patch again with the valid ranges for accumulate threshold set
to 1-255 as Al mentioned from the IPMI specs.

Thanks for the advice.  Hope this is seen as a useful patch.  Also please
feel free to rename the checker function however is seen most appropriate.

Vince
--- ipmitool-1.8.9/include/ipmitool/ipmi_sol.h.check-ranges	2006-03-19 12:59:39.000000000 -0500
+++ ipmitool-1.8.9/include/ipmitool/ipmi_sol.h	2007-08-07 11:27:45.000000000 -0400
@@ -75,6 +75,19 @@ struct activate_payload_rsp {
 } __attribute__ ((packed));
 
 
+/*
+ * Small function to validate that user-supplied SOL
+ * configuration parameter values we store in uint8_t
+ * data type falls within valid range.  With minval
+ * and maxval parameters we can use the same function
+ * to validate parameters that have different ranges
+ * of values.
+ */
+int ipmi_sol_set_param_isvalid_uint8_t( const long *value,
+					const char *param,
+					const uint8_t *minval,
+					const uint8_t *maxval);
+
 int ipmi_sol_main(struct ipmi_intf *, int, char **);
 int ipmi_get_sol_info(struct ipmi_intf             * intf,
 					  uint8_t                  channel,
--- ipmitool-1.8.9/lib/ipmi_sol.c.check-ranges	2007-01-11 13:36:25.000000000 -0500
+++ ipmitool-1.8.9/lib/ipmi_sol.c	2007-08-07 11:27:45.000000000 -0400
@@ -581,6 +581,37 @@ ipmi_print_sol_info(struct ipmi_intf * i
 
 
 /*
+ * Small function to validate that user-supplied SOL
+ * configuration parameter values we store in uint8_t
+ * data type falls within valid range.  With minval
+ * and maxval parameters we can use the same function
+ * to validate parameters that have different ranges
+ * of values.
+ *
+ * function will return 0 if value is not valid, or
+ * will return 1 if valid.
+ */
+
+
+int ipmi_sol_set_param_isvalid_uint8_t( const long *value,
+					const char *param,
+					const uint8_t *minval,
+					const uint8_t *maxval)
+
+{
+	if ( (strtol(value, NULL, 0) < minval) || (strtol(value, NULL, 0) > maxval))
+	{
+		lprintf(LOG_ERR, "Invalid value %s for parameter %s",
+			value, param);
+		lprintf(LOG_ERR, "Valid values are %d-%d", minval, maxval);
+		return 0;
+	}
+	else
+		return 1;
+}
+
+
+/*
  * ipmi_sol_set_param
  *
  * Set the specified Serial Over LAN value to the specified
@@ -777,7 +808,12 @@ ipmi_sol_set_param(struct ipmi_intf * in
 
 		req.msg.data_len = 4;
 		data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
-		data[2] = (uint8_t)strtol(value, NULL, 0);
+
+		/* validate user-supplied input */
+		if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 1, 255))
+			data[2] = (uint8_t)strtol(value, NULL, 0);
+		else
+			return -1;
 
 		/* We need other values to complete the request */
 		if (ipmi_get_sol_info(intf, channel, &params))
@@ -800,7 +836,12 @@ ipmi_sol_set_param(struct ipmi_intf * in
 
 		req.msg.data_len = 4;
 		data[1] = SOL_PARAMETER_CHARACTER_INTERVAL;
-		data[3] = (uint8_t)strtol(value, NULL, 0);
+
+		/* validate user-supplied input */
+		if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255))
+			data[3] = (uint8_t)strtol(value, NULL, 0);
+		else
+			return -1;
 
 		/* We need other values to complete the request */
 		if (ipmi_get_sol_info(intf, channel, &params))
@@ -823,7 +864,16 @@ ipmi_sol_set_param(struct ipmi_intf * in
 
 		req.msg.data_len = 4;
 		data[1] = SOL_PARAMETER_SOL_RETRY;
-		data[2] = (uint8_t)strtol(value, NULL, 0) & 0x07;
+
+		/* validate user input, 7 is max value */
+		if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 7))
+		{
+			data[2] = (uint8_t)strtol(value, NULL, 0);
+		}
+		else
+		{
+			return -1;
+		}
 
 		/* We need other values to complete the request */
 		if (ipmi_get_sol_info(intf, channel, &params))
@@ -846,7 +896,12 @@ ipmi_sol_set_param(struct ipmi_intf * in
 
 		req.msg.data_len = 4;
 		data[1] = SOL_PARAMETER_SOL_RETRY;
-		data[3] = (uint8_t)strtol(value, NULL, 0);
+
+		/* validate user-supplied input */
+		if (ipmi_sol_set_param_isvalid_uint8_t(value, param, 0, 255))
+			data[3] = (uint8_t)strtol(value, NULL, 0);
+		else
+			return -1;
 
 		/* We need other values to complete the request */
 		if (ipmi_get_sol_info(intf, channel, &params))
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Ipmitool-devel mailing list
Ipmitool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel

Reply via email to