]> granicus.if.org Git - shadow/commitdiff
* lib/getdef.c: Use getlong instead of strtol/strtoul.
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 10 Apr 2009 22:35:26 +0000 (22:35 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Fri, 10 Apr 2009 22:35:26 +0000 (22:35 +0000)
* libmisc/getlong, lib/getlong.c, libmisc/Makefile.am,
lib/Makefile.am: getlong.c moved from libmisc/ to lib/.

ChangeLog
lib/Makefile.am
lib/getdef.c
lib/getlong.c [moved from libmisc/getlong.c with 100% similarity]
libmisc/Makefile.am

index 207d56567d9e8e883ac67528f390c4f074711aaf..2d16aaae2671d3c34ab4381a405987bc8dd7b593 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-04-06  Nicolas François  <nicolas.francois@centraliens.net>
+
+       * lib/getdef.c: Use getlong instead of strtol/strtoul.
+       * libmisc/getlong, lib/getlong.c, libmisc/Makefile.am,
+       lib/Makefile.am: getlong.c moved from libmisc/ to lib/.
+
 2009-04-06  Nicolas François  <nicolas.francois@centraliens.net>
 
        * lib/shadow.c: Replace strtol() by getlong(). Also detect more
index ec0b116ecbf98b8e57c0deb95456123299a5683f..f993479562b6ee51b8afc02d3f53b40f9ee07090 100644 (file)
@@ -18,6 +18,7 @@ libshadow_la_SOURCES = \
        getdef.c \
        getdef.h \
        get_gid.c \
+       getlong.c \
        get_uid.c \
        groupio.c \
        groupmem.c \
index 6f4ab7060847f69e7c42fd72fcf03e4435a295e0..42e13a09056c06a7f1e704f85c5d1b2ad0a2effd 100644 (file)
@@ -193,6 +193,7 @@ bool getdef_bool (const char *item)
 int getdef_num (const char *item, int dflt)
 {
        struct itemdef *d;
+       long val;
 
        if (!def_loaded) {
                def_load ();
@@ -203,8 +204,16 @@ int getdef_num (const char *item, int dflt)
                return dflt;
        }
 
-       return (int) strtol (d->value, (char **) NULL, 0);
-       /* TODO: check for errors */
+       if (   (getlong (d->value, &val) == 0)
+           || (val > INT_MAX)
+           || (val < INT_MIN)) {
+               fprintf (stderr,
+                        _("configuration error - cannot parse %s value: '%s'"),
+                        item, d->value);
+               return dflt;
+       }
+
+       return (int) val;
 }
 
 
@@ -219,6 +228,7 @@ int getdef_num (const char *item, int dflt)
 unsigned int getdef_unum (const char *item, unsigned int dflt)
 {
        struct itemdef *d;
+       long val;
 
        if (!def_loaded) {
                def_load ();
@@ -229,8 +239,16 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
                return dflt;
        }
 
-       return (unsigned int) strtoul (d->value, (char **) NULL, 0);
-       /* TODO: check for errors */
+       if (   (getlong (d->value, &val) == 0)
+           || (val < 0)
+           || (val > INT_MAX)) {
+               fprintf (stderr,
+                        _("configuration error - cannot parse %s value: '%s'"),
+                        item, d->value);
+               return dflt;
+       }
+
+       return (unsigned int) val;
 }
 
 
@@ -245,6 +263,7 @@ unsigned int getdef_unum (const char *item, unsigned int dflt)
 long getdef_long (const char *item, long dflt)
 {
        struct itemdef *d;
+       long val;
 
        if (!def_loaded) {
                def_load ();
@@ -255,8 +274,14 @@ long getdef_long (const char *item, long dflt)
                return dflt;
        }
 
-       return strtol (d->value, (char **) NULL, 0);
-       /* TODO: check for errors */
+       if (getlong (d->value, &val) == 0) {
+               fprintf (stderr,
+                        _("configuration error - cannot parse %s value: '%s'"),
+                        item, d->value);
+               return dflt;
+       }
+
+       return val;
 }
 
 /*
@@ -270,6 +295,7 @@ long getdef_long (const char *item, long dflt)
 unsigned long getdef_ulong (const char *item, unsigned long dflt)
 {
        struct itemdef *d;
+       long val;
 
        if (!def_loaded) {
                def_load ();
@@ -280,8 +306,15 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
                return dflt;
        }
 
-       return (unsigned long) strtoul (d->value, (char **) NULL, 0);
-       /* TODO: check for errors */
+       if (getlong (d->value, &val) == 0) {
+               /* FIXME: we should have a getulong */
+               fprintf (stderr,
+                        _("configuration error - cannot parse %s value: '%s'"),
+                        item, d->value);
+               return dflt;
+       }
+
+       return val;
 }
 
 /*
@@ -354,9 +387,8 @@ static struct itemdef *def_find (const char *name)
         */
 
        fprintf (stderr,
-                _
-                ("configuration error - unknown item '%s' (notify administrator)\n"),
-                name);
+                _("configuration error - unknown item '%s' (notify administrator)\n"),
+                name);
        SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
        return (struct itemdef *) NULL;
 }
similarity index 100%
rename from libmisc/getlong.c
rename to lib/getlong.c
index c04125e7a4e72f6b31bdad6b0baa5f42e26efc41..e905d8796b590b814e5222bdd380ff73f1f1e38d 100644 (file)
@@ -29,7 +29,6 @@ libmisc_a_SOURCES = \
        getdate.h \
        getdate.y \
        getgr_nam_gid.c \
-       getlong.c \
        getrange.c \
        hushed.c \
        isexpired.c \