From: Ken Raeburn Date: Tue, 4 Jun 2002 06:38:24 +0000 (+0000) Subject: * prof_get.c (profile_get_integer): Set errno to 0 before strtol call, so we X-Git-Tag: krb5-1.3-alpha1~738 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=53c8f6650caef85bb9b38f23e0e50965d50d26f6;p=krb5.git * 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. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14464 dc483132-0cff-0310-8789-dd5450dbe970 --- 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 + + * 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 * 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;