Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh While doing the previous change, I noticed that when ...



details:   https://anonhg.NetBSD.org/src/rev/a06fd73cdf96
branches:  trunk
changeset: 365257:a06fd73cdf96
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Apr 16 14:23:36 2022 +0000

description:
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:

 bin/sh/miscbltin.c |  14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diffs (48 lines):

diff -r f13079c2d608 -r a06fd73cdf96 bin/sh/miscbltin.c
--- a/bin/sh/miscbltin.c        Sat Apr 16 14:20:45 2022 +0000
+++ b/bin/sh/miscbltin.c        Sat Apr 16 14:23:36 2022 +0000
@@ -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 @@
 umaskcmd(int argc, char **argv)
 {
        char *ap;
-       int mask;
+       mode_t mask;
        int i;
        int symbolic_mode = 0;
 
@@ -265,13 +265,19 @@
                }
        } 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;



Home | Main Index | Thread Index | Old Index