diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-07-02 13:58:07 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2004-07-02 13:58:07 +0000 |
commit | 17b97e795b39ac51ad52ecbde65f26cff0e6b894 (patch) | |
tree | c9239d107416fc1f29709d66d34eef8d37528c64 | |
parent | 806bc65972c0c7af114b306e5c0da7afdf49fd14 (diff) |
deregister, better use of strtoul and always set ERANGE on invalid octal
permission. ok millert@; man page ok jmc@
-rw-r--r-- | lib/libc/gen/setmode.3 | 7 | ||||
-rw-r--r-- | lib/libc/gen/setmode.c | 37 |
2 files changed, 21 insertions, 23 deletions
diff --git a/lib/libc/gen/setmode.3 b/lib/libc/gen/setmode.3 index eac3d423bda..bcca49c5118 100644 --- a/lib/libc/gen/setmode.3 +++ b/lib/libc/gen/setmode.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: setmode.3,v 1.9 2003/06/02 20:18:34 millert Exp $ +.\" $OpenBSD: setmode.3,v 1.10 2004/07/02 13:58:06 otto Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -88,7 +88,10 @@ The function may fail and set .Va errno for any of the errors specified for the library routine -.Xr malloc 3 . +.Xr malloc 3 +or to +.Er ERANGE +if an invalid octal value was specified. .Sh SEE ALSO .Xr chmod 1 , .Xr stat 2 , diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 9ed72f5ec0a..880fe192d2c 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setmode.c,v 1.14 2004/07/01 07:28:01 otto Exp $ */ +/* $OpenBSD: setmode.c,v 1.15 2004/07/02 13:58:06 otto Exp $ */ /* $NetBSD: setmode.c,v 1.15 1997/02/07 22:21:06 christos Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: setmode.c,v 1.14 2004/07/01 07:28:01 otto Exp $"; +static char rcsid[] = "$OpenBSD: setmode.c,v 1.15 2004/07/02 13:58:06 otto Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -84,8 +84,8 @@ static void dumpmode(BITCMD *); mode_t getmode(const void *bbox, mode_t omode) { - register const BITCMD *set; - register mode_t clrval, newmode, value; + const BITCMD *set; + mode_t clrval, newmode, value; set = (const BITCMD *)bbox; newmode = omode; @@ -151,13 +151,11 @@ common: if (set->cmd2 & CMD2_CLR) { #define ADDCMD(a, b, c, d) \ if (set >= endset) { \ - register BITCMD *newset; \ + BITCMD *newset; \ setlen += SET_LEN_INCR; \ newset = realloc(saveset, sizeof(BITCMD) * setlen); \ - if (!newset) { \ - if (saveset) \ - free(saveset); \ - saveset = NULL; \ + if (newset == NULL) { \ + free(saveset); \ return (NULL); \ } \ set = newset + (set - saveset); \ @@ -171,13 +169,13 @@ common: if (set->cmd2 & CMD2_CLR) { void * setmode(const char *p) { - register int perm, who; - register char op; + int perm, who; + char op, *ep; BITCMD *set, *saveset, *endset; sigset_t sigset, sigoset; mode_t mask; int equalopdone, permXbits, setlen; - long perml; + u_long perml; if (!*p) return (NULL); @@ -206,17 +204,14 @@ setmode(const char *p) * or illegal bits. */ if (isdigit(*p)) { - perml = strtol(p, NULL, 8); - if (perml < 0 || (perml & ~(STANDARD_BITS|S_ISTXT))) { + perml = strtoul(p, &ep, 8); + /* The test on perml will also catch overflow. */ + if (*ep != '\0' || (perml & ~(STANDARD_BITS|S_ISTXT))) { + errno = ERANGE; free(saveset); return (NULL); } perm = (mode_t)perml; - while (*++p) - if (*p < '0' || *p > '7') { - free(saveset); - return (NULL); - } ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); set->cmd = 0; return (saveset); @@ -413,8 +408,8 @@ dumpmode(BITCMD *set) static void compress_mode(BITCMD *set) { - register BITCMD *nset; - register int setbits, clrbits, Xbits, op; + BITCMD *nset; + int setbits, clrbits, Xbits, op; for (nset = set;;) { /* Copy over any 'u', 'g' and 'o' commands. */ |