From: nekral-guest Date: Fri, 10 Apr 2009 22:35:26 +0000 (+0000) Subject: * lib/getdef.c: Use getlong instead of strtol/strtoul. X-Git-Tag: 4.1.3~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84f5ca951c5a11decd47fa9ffde8d16405c14e61;p=shadow * 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/. --- diff --git a/ChangeLog b/ChangeLog index 207d5656..2d16aaae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-04-06 Nicolas François + + * 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 * lib/shadow.c: Replace strtol() by getlong(). Also detect more diff --git a/lib/Makefile.am b/lib/Makefile.am index ec0b116e..f9934795 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,6 +18,7 @@ libshadow_la_SOURCES = \ getdef.c \ getdef.h \ get_gid.c \ + getlong.c \ get_uid.c \ groupio.c \ groupmem.c \ diff --git a/lib/getdef.c b/lib/getdef.c index 6f4ab706..42e13a09 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -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; } diff --git a/libmisc/getlong.c b/lib/getlong.c similarity index 100% rename from libmisc/getlong.c rename to lib/getlong.c diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am index c04125e7..e905d879 100644 --- a/libmisc/Makefile.am +++ b/libmisc/Makefile.am @@ -29,7 +29,6 @@ libmisc_a_SOURCES = \ getdate.h \ getdate.y \ getgr_nam_gid.c \ - getlong.c \ getrange.c \ hushed.c \ isexpired.c \