Permalink
Browse files

* prof_get.c: Fixed bug where profile_get_integer was assuming that s…

…trtol resets errno when there isn't an error. Fixed error handling.

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/meeroh-profile-sharing-optimization@14531 dc483132-0cff-0310-8789-dd5450dbe970
  • Loading branch information...
1 parent 5915e60 commit ad3df74c6d2c572e20c4734999be5a72cf20f302 lxs committed Jun 18, 2002
Showing with 22 additions and 10 deletions.
  1. +4 −0 src/util/profile/ChangeLog
  2. +18 −10 src/util/profile/prof_get.c
@@ -1,3 +1,7 @@
+2002-06-18 Alexandra Ellwood <lxs@mit.edu>
+ * prof_get.c: Fixed bug where profile_get_integer was assuming that strtol
+ resets errno when there isn't an error. Fixed error handling.
+
2002-06-05 Alexandra Ellwood <lxs@mit.edu>
* prof_threads.[ch]: Added prof_mutex_destroy so we don't leak memory
on library unload.
@@ -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,14 +269,23 @@ profile_get_integer(profile, name, subname, subsubname,
return 0;
} else if (retval)
return retval;
-
- 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)) {
- return PROF_BAD_INTEGER;
- }
+ /* Empty string is no good. */
+ if (value[0] == 0)
+ return PROF_BAD_INTEGER;
+ errno = 0;
+
+ ret_long = strtol (value, &end_value, 10);
+
+ /* 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;
return 0;

0 comments on commit ad3df74

Please sign in to comment.