Hello,I fixed patch sent by Vince Worthington to actually work. It checks input ranges of 'ipmitool sol set' parameters and prints meaningful error messages when the provided value is out of acceptable range.
Find the original patch at https://sourceforge.net/mailarchive/forum.php?thread_name=27988.66.187.233.202.1186508444.squirrel%40www.lvwnet.com&forum_name=ipmitool-devel
Jan
Index: include/ipmitool/ipmi_sol.h =================================================================== RCS file: /cvsroot/ipmitool/ipmitool/include/ipmitool/ipmi_sol.h,v retrieving revision 1.8 diff -u -r1.8 ipmi_sol.h --- include/ipmitool/ipmi_sol.h 29 Sep 2008 18:26:16 -0000 1.8 +++ include/ipmitool/ipmi_sol.h 15 Jan 2009 12:01:32 -0000 @@ -81,6 +81,24 @@ #pramga pack(0) #endif +/* + * 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 -1 if value is not valid, or + * will return 0 if valid. + */ +int ipmi_sol_set_param_isvalid_uint8_t( const char *strval, + const char *name, + int base, + uint8_t minval, + uint8_t maxval, + uint8_t *out_value); + int ipmi_sol_main(struct ipmi_intf *, int, char **); int ipmi_get_sol_info(struct ipmi_intf * intf, uint8_t channel, Index: lib/ipmi_sol.c =================================================================== RCS file: /cvsroot/ipmitool/ipmitool/lib/ipmi_sol.c,v retrieving revision 1.54 diff -u -r1.54 ipmi_sol.c --- lib/ipmi_sol.c 9 Jan 2009 23:22:16 -0000 1.54 +++ lib/ipmi_sol.c 15 Jan 2009 12:01:32 -0000 @@ -633,6 +633,42 @@ /* + * 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 -1 if value is not valid, or + * will return 0 if valid. + */ +int ipmi_sol_set_param_isvalid_uint8_t( const char *strval, + const char *name, + int base, + uint8_t minval, + uint8_t maxval, + uint8_t *out_value) +{ + char *end; + long val = strtol(strval, &end, base); + + if ((val < minval) + || (val > maxval) + || (*end != '\0')) { + lprintf(LOG_ERR, "Invalid value %s for parameter %s", + strval, name); + lprintf(LOG_ERR, "Valid values are %d-%d", minval, maxval); + return -1; + } + else { + *out_value = val; + return 0; + } +} + + +/* * ipmi_sol_set_param * * Set the specified Serial Over LAN value to the specified @@ -829,7 +865,10 @@ 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, 0, 1, 255, &data[2])) + return -1; /* We need other values to complete the request */ if (ipmi_get_sol_info(intf, channel, ¶ms)) @@ -852,7 +891,10 @@ 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, 0, 255, &data[3])) + return -1; /* We need other values to complete the request */ if (ipmi_get_sol_info(intf, channel, ¶ms)) @@ -875,7 +917,10 @@ 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, 0, 7, &data[2])) + return -1; /* We need other values to complete the request */ if (ipmi_get_sol_info(intf, channel, ¶ms)) @@ -898,7 +943,10 @@ 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, 0, 255, &data[3])) + return -1; /* We need other values to complete the request */ if (ipmi_get_sol_info(intf, channel, ¶ms))
------------------------------------------------------------------------------ This SF.net email is sponsored by: SourcForge Community SourceForge wants to tell your story. http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________ Ipmitool-devel mailing list Ipmitool-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ipmitool-devel