diff options
| author | kre <kre@NetBSD.org> | 2022-04-16 14:23:36 +0000 |
|---|---|---|
| committer | kre <kre@NetBSD.org> | 2022-04-16 14:23:36 +0000 |
| commit | 078eea82ddbeb00a206c5d412296e261f7e7e642 (patch) | |
| tree | e5b25321c117014685cf5681ad8970285d5a1536 /bin | |
| parent | b0923ea0cf4e5f206f90318ac09b926263e693d0 (diff) | |
While doing the previous change, I noticed that when used in a
particularly perverse way, the error message for a bad octal
constant as the new umask value could incorrectly claim that the
-S option (which would need to be present to cause this issue)
was the detected bad value. Fix that to report the actual
incorrect arg.
And while fiddling, also check for args to umask that are too big
to be sane mask values (the biggest permitted is 07777) and use
mode_t as the mask variable type, rather than int.
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/miscbltin.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/bin/sh/miscbltin.c b/bin/sh/miscbltin.c index ffdf13f59ca..66c47dd9002 100644 --- a/bin/sh/miscbltin.c +++ b/bin/sh/miscbltin.c @@ -1,4 +1,4 @@ -/* $NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $ */ +/* $NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: miscbltin.c,v 1.48 2022/04/16 14:20:45 kre Exp $"); +__RCSID("$NetBSD: miscbltin.c,v 1.49 2022/04/16 14:23:36 kre Exp $"); #endif #endif /* not lint */ @@ -215,7 +215,7 @@ int umaskcmd(int argc, char **argv) { char *ap; - int mask; + mode_t mask; int i; int symbolic_mode = 0; @@ -265,13 +265,19 @@ umaskcmd(int argc, char **argv) } } else { if (isdigit((unsigned char)*ap)) { + int range = 0; + mask = 0; do { if (*ap >= '8' || *ap < '0') error("Not a valid octal number: '%s'", - argv[1]); + *argptr); mask = (mask << 3) + (*ap - '0'); + if (mask & ~07777) + range = 1; } while (*++ap != '\0'); + if (range) + error("Mask constant '%s' out of range", *argptr); umask(mask); } else { void *set; |
