diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2002-06-04 06:38:24 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2002-06-04 06:38:24 +0000 |
| commit | 53c8f6650caef85bb9b38f23e0e50965d50d26f6 (patch) | |
| tree | 629f0353e9b3207add730e75262839b7d5f3b9c3 /src/util | |
| parent | 3bbc4a188f236a8944eaadc20439b6c3cf372a8d (diff) | |
| download | krb5-53c8f6650caef85bb9b38f23e0e50965d50d26f6.tar.gz krb5-53c8f6650caef85bb9b38f23e0e50965d50d26f6.tar.xz krb5-53c8f6650caef85bb9b38f23e0e50965d50d26f6.zip | |
* 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
Diffstat (limited to 'src/util')
| -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 660e1344cc..53c8641cea 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 cd9d6b5c0c..281066e439 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; |
