diff options
author | Rob Landley <rob@landley.net> | 2014-08-15 10:50:39 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-08-15 10:50:39 -0500 |
commit | 3b5b19e7bf4598536bc7ef501598c0f6e28e4e5a (patch) | |
tree | eedda2ccce43ff11bc8bc830bcd0b665cb523444 /lib | |
parent | be3a48c269cfa4cf35e0bb31155553a8d3c6d6c1 (diff) | |
download | toybox-3b5b19e7bf4598536bc7ef501598c0f6e28e4e5a.tar.gz |
If string_to_mode() is called on a base mode with S_ISDIR() and such set, pass those extra bits through.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -686,15 +686,16 @@ char *num_to_sig(int sig) // premute mode bits based on posix mode strings. mode_t string_to_mode(char *modestr, mode_t mode) { - char *whos = "ogua", *hows = "=+-", *whats = "xwrstX", *whys = "ogu"; - char *s, *str = modestr; + char *whos = "ogua", *hows = "=+-", *whats = "xwrstX", *whys = "ogu", + *s, *str = modestr; + mode_t extrabits = mode & ~(07777); // Handle octal mode if (isdigit(*str)) { mode = strtol(str, &s, 8); if (*s || (mode & ~(07777))) goto barf; - return mode; + return mode | extrabits; } // Gaze into the bin of permission... @@ -762,7 +763,8 @@ mode_t string_to_mode(char *modestr, mode_t mode) if (!*str) break; } - return mode; + + return mode|extrabits; barf: error_exit("bad mode '%s'", modestr); } |