diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/util/profile/ChangeLog | 6 | ||||
| -rw-r--r-- | src/util/profile/prof_get.c | 24 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 660e1344c..53c8641ce 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,9 @@ +2002-06-04 Ken Raeburn <raeburn@mit.edu> + + * prof_get.c (profile_get_integer): Set errno to 0 before strtol + call, so we can distinguish error from LONG_MIN/MAX. Break out + different error conditions and comment them. + 2002-05-08 Ken Raeburn <raeburn@mit.edu> * prof_get.c (conf_yes, conf_no): Now const. diff --git a/src/util/profile/prof_get.c b/src/util/profile/prof_get.c index cd9d6b5c0..281066e43 100644 --- a/src/util/profile/prof_get.c +++ b/src/util/profile/prof_get.c @@ -255,10 +255,9 @@ profile_get_integer(profile, name, subname, subsubname, char *end_value; long ret_long; - if (profile == 0) { - *ret_int = def_val; + *ret_int = def_val; + if (profile == 0) return 0; - } names[0] = name; names[1] = subname; @@ -270,13 +269,22 @@ profile_get_integer(profile, name, subname, subsubname, return 0; } else if (retval) return retval; - + + if (value[0] == 0) + /* Empty string is no good. */ + return PROF_BAD_INTEGER; + errno = 0; ret_long = strtol (value, &end_value, 10); - if ((errno != 0) || (end_value != value + strlen (value)) || - (end_value == value) || (ret_long > INT_MAX) || - (ret_long < INT_MIN)) { + + /* Overflow or underflow. */ + if ((ret_long == LONG_MIN || ret_long == LONG_MAX) && errno != 0) + return PROF_BAD_INTEGER; + /* Value outside "int" range. */ + if ((long) (int) ret_long != ret_long) + return PROF_BAD_INTEGER; + /* Garbage in string. */ + if (end_value != value + strlen (value)) return PROF_BAD_INTEGER; - } *ret_int = ret_long; |
