[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] hush: Correctly set octal umask values
From:       Stephen Heumann <stephenheumann () gmail ! com>
Date:       2015-07-21 5:52:50
Message-ID: 1437457970-7686-1-git-send-email-stephenheumann () gmail ! com
[Download RAW message or body]

The umask was being set to the complement of the value specified.
This complement operation should only be applied to symbolic
mode specifications, not octal ones.

To distinguish the two types of mode specifications, make
bb_parse_mode return different values for them.  This shouldn't
affect other uses of bb_parse_mode, since they only check if
the return value is zero or not.

Signed-off-by: Stephen Heumann <stephenheumann@gmail.com>
---
 libbb/parse_mode.c | 3 ++-
 shell/hush.c       | 6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c
index 5a4e1c5..b0ea7e5 100644
--- a/libbb/parse_mode.c
+++ b/libbb/parse_mode.c
@@ -15,6 +15,7 @@
 
 #define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
 
+/* Returns 1 if mode specification was octal, 2 if symbolic, 0 if invalid */
 int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
 {
 	static const mode_t who_mask[] = {
@@ -146,5 +147,5 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode)
 	}
 
 	*current_mode = new_mode;
-	return 1;
+	return 2;
 }
diff --git a/shell/hush.c b/shell/hush.c
index 3ca0449..0ba4c71 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8957,8 +8957,10 @@ static int FAST_FUNC builtin_umask(char **argv)
 
 		mask ^= 0777;
 		rc = bb_parse_mode(argv[0], &mask);
-		mask ^= 0777;
-		if (rc == 0) {
+		if (rc == 2) {
+			/* Symbolic (not octal) mode: umask is the complement */
+			mask ^= 0777;
+		} else if (rc == 0) {
 			mask = old_mask;
 			/* bash messages:
 			 * bash: umask: 'q': invalid symbolic mode operator
-- 
1.9.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic