aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-07 16:56:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-07 16:56:20 +0200
commit6283f9828320ef5e0be0b060b7f26522b529ed42 (patch)
tree9b11416a3cdd3655f2854debe868e4c19d232a88
parent9c5410023a9d1920c336ed4d9ceaad586ce43328 (diff)
downloadbusybox-w32-6283f9828320ef5e0be0b060b7f26522b529ed42.tar.gz
busybox-w32-6283f9828320ef5e0be0b060b7f26522b529ed42.tar.bz2
busybox-w32-6283f9828320ef5e0be0b060b7f26522b529ed42.zip
hush: fix umask: umask(022) was setting umask(755)
Based on the patch by Rich Felker <dalias@libc.org> function old new delta builtin_umask 121 161 +40 umaskcmd 318 279 -39 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c36
-rw-r--r--shell/hush.c10
2 files changed, 21 insertions, 25 deletions
diff --git a/shell/ash.c b/shell/ash.c
index b34dcc149..2669157bc 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12814,7 +12814,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12814} 12814}
12815 12815
12816static int FAST_FUNC 12816static int FAST_FUNC
12817umaskcmd(int argc UNUSED_PARAM, char **argv) 12817umaskcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12818{ 12818{
12819 static const char permuser[3] ALIGN1 = "ugo"; 12819 static const char permuser[3] ALIGN1 = "ugo";
12820 static const char permmode[3] ALIGN1 = "rwx"; 12820 static const char permmode[3] ALIGN1 = "rwx";
@@ -12824,9 +12824,6 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
12824 S_IROTH, S_IWOTH, S_IXOTH 12824 S_IROTH, S_IWOTH, S_IXOTH
12825 }; 12825 };
12826 12826
12827 /* TODO: use bb_parse_mode() instead */
12828
12829 char *ap;
12830 mode_t mask; 12827 mode_t mask;
12831 int i; 12828 int i;
12832 int symbolic_mode = 0; 12829 int symbolic_mode = 0;
@@ -12840,8 +12837,7 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
12840 umask(mask); 12837 umask(mask);
12841 INT_ON; 12838 INT_ON;
12842 12839
12843 ap = *argptr; 12840 if (*argptr == NULL) {
12844 if (ap == NULL) {
12845 if (symbolic_mode) { 12841 if (symbolic_mode) {
12846 char buf[18]; 12842 char buf[18];
12847 char *p = buf; 12843 char *p = buf;
@@ -12858,27 +12854,23 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
12858 } 12854 }
12859 *p++ = ','; 12855 *p++ = ',';
12860 } 12856 }
12861 *--p = 0; 12857 *--p = '\0';
12862 puts(buf); 12858 puts(buf);
12863 } else { 12859 } else {
12864 out1fmt("%.4o\n", mask); 12860 out1fmt("%.4o\n", mask);
12865 } 12861 }
12866 } else { 12862 } else {
12867 if (isdigit((unsigned char) *ap)) { 12863 char *modestr = *argptr;
12868 mask = 0; 12864 /* numeric umasks are taken as-is */
12869 do { 12865 /* symbolic umasks are inverted: "umask a=rx" calls umask(222) */
12870 if (*ap >= '8' || *ap < '0') 12866 if (!isdigit(modestr[0]))
12871 ash_msg_and_raise_error(msg_illnum, argv[1]); 12867 mask ^= 0777;
12872 mask = (mask << 3) + (*ap - '0'); 12868 if (!bb_parse_mode(modestr, &mask) || (unsigned)mask > 0777) {
12873 } while (*++ap != '\0'); 12869 ash_msg_and_raise_error("illegal mode: %s", modestr);
12874 umask(mask); 12870 }
12875 } else { 12871 if (!isdigit(modestr[0]))
12876 mask = ~mask & 0777; 12872 mask ^= 0777;
12877 if (!bb_parse_mode(ap, &mask)) { 12873 umask(mask);
12878 ash_msg_and_raise_error("illegal mode: %s", ap);
12879 }
12880 umask(~mask & 0777);
12881 }
12882 } 12874 }
12883 return 0; 12875 return 0;
12884} 12876}
diff --git a/shell/hush.c b/shell/hush.c
index 752080a64..8b8d5fc8b 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8970,10 +8970,14 @@ static int FAST_FUNC builtin_umask(char **argv)
8970 if (argv[0]) { 8970 if (argv[0]) {
8971 mode_t old_mask = mask; 8971 mode_t old_mask = mask;
8972 8972
8973 mask ^= 0777; 8973 /* numeric umasks are taken as-is */
8974 /* symbolic umasks are inverted: "umask a=rx" calls umask(222) */
8975 if (!isdigit(argv[0][0]))
8976 mask ^= 0777;
8974 rc = bb_parse_mode(argv[0], &mask); 8977 rc = bb_parse_mode(argv[0], &mask);
8975 mask ^= 0777; 8978 if (!isdigit(argv[0][0]))
8976 if (rc == 0) { 8979 mask ^= 0777;
8980 if (rc == 0 || (unsigned)mask > 0777) {
8977 mask = old_mask; 8981 mask = old_mask;
8978 /* bash messages: 8982 /* bash messages:
8979 * bash: umask: 'q': invalid symbolic mode operator 8983 * bash: umask: 'q': invalid symbolic mode operator