Re: switch -u takes negative number
Tomasz Kłoczko <[email protected]> Sun, 23 Jul 2006 21:06:53 +0200
| Newsgroups | gmane.linux.pld.shadow.general |
|---|---|
| Message-ID | <1153681491.23968.3.camel@kloczek01> |
--=-po73eHkpt8IgFRMHsF11
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Dnia 18-07-2006, wto o godzinie 14:25 +0200, Peter Vrabec napisał(a):
> fixed and improved patch in attachment
After rewiew strtoul() documetations I found another way of fixing this
kind errors (patch in attachemt).
Current post strtoul() checking is of course incorrect but looks like
checking errorno variable it is all what is neccessary.
kloczek
--=-po73eHkpt8IgFRMHsF11
Content-Disposition: attachment; filename=shadow-UID_GID.patch
Content-Type: text/x-patch; name=shadow-UID_GID.patch; charset=utf-8
Content-Transfer-Encoding: 7bit
Index: src/groupadd.c
===================================================================
RCS file: /cvsroot/shadow/src/groupadd.c,v
retrieving revision 1.54
diff -u -r1.54 groupadd.c
--- src/groupadd.c 14 Jul 2006 19:24:40 -0000 1.54
+++ src/groupadd.c 23 Jul 2006 18:55:59 -0000
@@ -431,7 +431,7 @@
usage ();
group_id = strtoul (optarg, &cp, 10);
- if (*cp != '\0') {
+ if (errno) {
fprintf (stderr,
_("%s: invalid group %s\n"),
Prog, optarg);
Index: src/groupmod.c
===================================================================
RCS file: /cvsroot/shadow/src/groupmod.c,v
retrieving revision 1.40
diff -u -r1.40 groupmod.c
--- src/groupmod.c 11 Jul 2006 21:58:47 -0000 1.40
+++ src/groupmod.c 23 Jul 2006 18:55:59 -0000
@@ -345,7 +345,7 @@
case 'g':
gflg++;
group_newid = strtoul (optarg, &end, 10);
- if (*end != '\0') {
+ if (errno) {
fprintf (stderr,
_("%s: invalid group %s\n"),
Prog, optarg);
Index: src/useradd.c
===================================================================
RCS file: /cvsroot/shadow/src/useradd.c,v
retrieving revision 1.99
diff -u -r1.99 useradd.c
--- src/useradd.c 22 Jun 2006 11:30:32 -0000 1.99
+++ src/useradd.c 23 Jul 2006 18:55:59 -0000
@@ -204,7 +204,11 @@
char *ep;
gid = strtoul (name, &ep, 10);
- if (*name != '\0' && *ep == '\0') /* valid numeric GID */
+ if (errno) {
+ fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
+ name);
+ exit (E_BAD_ARG);
+ } else
return getgrgid (gid);
return getgrnam (name);
@@ -229,11 +233,12 @@
char *ep;
val = strtoul (cp, &ep, 10);
- if (*cp != '\0' && *ep == '\0') /* valid number */
+ if (errno) {
+ fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
+ cp);
+ exit (E_BAD_ARG);
+ } else
return val;
-
- fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
- exit (E_BAD_ARG);
}
#define MATCH(x,y) (strncmp((x),(y),strlen(y)) == 0)
Index: src/usermod.c
===================================================================
RCS file: /cvsroot/shadow/src/usermod.c,v
retrieving revision 1.70
diff -u -r1.70 usermod.c
--- src/usermod.c 12 Jul 2006 14:23:14 -0000 1.70
+++ src/usermod.c 23 Jul 2006 18:55:59 -0000
@@ -166,7 +166,11 @@
char *ep;
gid = strtoul (name, &ep, 10);
- if (*name != '\0' && *ep == '\0') /* valid numeric GID */
+ if (errno) {
+ fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
+ name);
+ exit (E_BAD_ARG);
+ } else
return getgrgid (gid);
return getgrnam (name);
@@ -823,11 +827,13 @@
char *ep;
val = strtoul (cp, &ep, 10);
- if (*cp != '\0' && *ep == '\0') /* valid number */
+ if (errno) {
+ fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
+ cp);
+ exit (E_BAD_ARG);
+ } else
return val;
- fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
- exit (E_BAD_ARG);
}
/*
--=-po73eHkpt8IgFRMHsF11
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline