* prof_get.c (profile_get_integer): Set errno to 0 before strtol call, so we
authorKen Raeburn <raeburn@mit.edu>
Tue, 4 Jun 2002 06:38:24 +0000 (06:38 +0000)
committerKen Raeburn <raeburn@mit.edu>
Tue, 4 Jun 2002 06:38:24 +0000 (06:38 +0000)
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

src/util/profile/ChangeLog
src/util/profile/prof_get.c

index 660e1344cc532974ef758506b3e383aa3d62ef47..53c8641cea29ab830cc48b6330f3b395a3a05180 100644 (file)
@@ -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.
index cd9d6b5c0c3d9f2aac53173294b2df26049e7742..281066e4399afbf51c23b9e7174b4daefc526e7b 100644 (file)
@@ -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;