+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
int getdef_num (const char *item, int dflt)
{
struct itemdef *d;
+ long val;
if (!def_loaded) {
def_load ();
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;
}
unsigned int getdef_unum (const char *item, unsigned int dflt)
{
struct itemdef *d;
+ long val;
if (!def_loaded) {
def_load ();
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;
}
long getdef_long (const char *item, long dflt)
{
struct itemdef *d;
+ long val;
if (!def_loaded) {
def_load ();
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;
}
/*
unsigned long getdef_ulong (const char *item, unsigned long dflt)
{
struct itemdef *d;
+ long val;
if (!def_loaded) {
def_load ();
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;
}
/*
*/
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;
}