[Pkg-shadow-commits] r2622 - in upstream/trunk: . lib libmisc

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Fri Apr 10 22:35:26 UTC 2009


Author: nekral-guest
Date: 2009-04-10 22:35:26 +0000 (Fri, 10 Apr 2009)
New Revision: 2622

Added:
   upstream/trunk/lib/getlong.c
Removed:
   upstream/trunk/libmisc/getlong.c
Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/lib/Makefile.am
   upstream/trunk/lib/getdef.c
   upstream/trunk/libmisc/Makefile.am
Log:
	* 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/.

Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-04-10 22:35:19 UTC (rev 2621)
+++ upstream/trunk/ChangeLog	2009-04-10 22:35:26 UTC (rev 2622)
@@ -1,5 +1,11 @@
 2009-04-06  Nicolas François  <nicolas.francois at 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 at centraliens.net>
+
 	* lib/shadow.c: Replace strtol() by getlong(). Also detect more
 	issues in a numerical shadow entry field.
 

Modified: upstream/trunk/lib/Makefile.am
===================================================================
--- upstream/trunk/lib/Makefile.am	2009-04-10 22:35:19 UTC (rev 2621)
+++ upstream/trunk/lib/Makefile.am	2009-04-10 22:35:26 UTC (rev 2622)
@@ -18,6 +18,7 @@
 	getdef.c \
 	getdef.h \
 	get_gid.c \
+	getlong.c \
 	get_uid.c \
 	groupio.c \
 	groupmem.c \

Modified: upstream/trunk/lib/getdef.c
===================================================================
--- upstream/trunk/lib/getdef.c	2009-04-10 22:35:19 UTC (rev 2621)
+++ upstream/trunk/lib/getdef.c	2009-04-10 22:35:26 UTC (rev 2622)
@@ -193,6 +193,7 @@
 int getdef_num (const char *item, int dflt)
 {
 	struct itemdef *d;
+	long val;
 
 	if (!def_loaded) {
 		def_load ();
@@ -203,8 +204,16 @@
 		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 @@
 unsigned int getdef_unum (const char *item, unsigned int dflt)
 {
 	struct itemdef *d;
+	long val;
 
 	if (!def_loaded) {
 		def_load ();
@@ -229,8 +239,16 @@
 		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 @@
 long getdef_long (const char *item, long dflt)
 {
 	struct itemdef *d;
+	long val;
 
 	if (!def_loaded) {
 		def_load ();
@@ -255,8 +274,14 @@
 		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 @@
 unsigned long getdef_ulong (const char *item, unsigned long dflt)
 {
 	struct itemdef *d;
+	long val;
 
 	if (!def_loaded) {
 		def_load ();
@@ -280,8 +306,15 @@
 		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 @@
 	 */
 
 	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;
 }

Copied: upstream/trunk/lib/getlong.c (from rev 2621, upstream/trunk/libmisc/getlong.c)
===================================================================
--- upstream/trunk/lib/getlong.c	                        (rev 0)
+++ upstream/trunk/lib/getlong.c	2009-04-10 22:35:26 UTC (rev 2622)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2007 - 2009, Nicolas François
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the copyright holders or contributors may not be used to
+ *    endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#ident "$Id$"
+
+#include <stdlib.h>
+#include <errno.h>
+#include "prototypes.h"
+
+int getlong (const char *numstr, long int *result)
+{
+	long val;
+	char *endptr;
+
+	errno = 0;
+	val = strtol (numstr, &endptr, 10);
+	if (('\0' == numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
+		return 0;
+	}
+
+	*result = val;
+	return 1;
+}
+

Modified: upstream/trunk/libmisc/Makefile.am
===================================================================
--- upstream/trunk/libmisc/Makefile.am	2009-04-10 22:35:19 UTC (rev 2621)
+++ upstream/trunk/libmisc/Makefile.am	2009-04-10 22:35:26 UTC (rev 2622)
@@ -29,7 +29,6 @@
 	getdate.h \
 	getdate.y \
 	getgr_nam_gid.c \
-	getlong.c \
 	getrange.c \
 	hushed.c \
 	isexpired.c \

Deleted: upstream/trunk/libmisc/getlong.c
===================================================================
--- upstream/trunk/libmisc/getlong.c	2009-04-10 22:35:19 UTC (rev 2621)
+++ upstream/trunk/libmisc/getlong.c	2009-04-10 22:35:26 UTC (rev 2622)
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2007 - 2009, Nicolas François
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the copyright holders or contributors may not be used to
- *    endorse or promote products derived from this software without
- *    specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <config.h>
-
-#ident "$Id$"
-
-#include <stdlib.h>
-#include <errno.h>
-#include "prototypes.h"
-
-int getlong (const char *numstr, long int *result)
-{
-	long val;
-	char *endptr;
-
-	errno = 0;
-	val = strtol (numstr, &endptr, 10);
-	if (('\0' == numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
-		return 0;
-	}
-
-	*result = val;
-	return 1;
-}
-




More information about the Pkg-shadow-commits mailing list