Module Name:    src
Committed By:   kre
Date:           Sat Apr 16 14:23:36 UTC 2022

Modified Files:
        src/bin/sh: miscbltin.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/bin/sh/miscbltin.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/miscbltin.c
diff -u src/bin/sh/miscbltin.c:1.48 src/bin/sh/miscbltin.c:1.49
--- src/bin/sh/miscbltin.c:1.48	Sat Apr 16 14:20:45 2022
+++ src/bin/sh/miscbltin.c	Sat Apr 16 14:23:36 2022
@@ -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;

Reply via email to