FreeBSD Bugzilla – Attachment 97864 Details for
Bug 136669
[libc] [patch] setmode(3) should always set errno on error
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 3.29 KB, created by
Yair K.
on 2009-07-12 00:00:06 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Yair K.
Created:
2009-07-12 00:00:06 UTC
Size:
3.29 KB
patch
obsolete
>--- setmode.c 2009-07-11 22:11:49.832306655 +0300 >+++ setmode.c 2009-07-11 22:21:26.175049175 +0300 >@@ -41,6 +41,7 @@ > #include <sys/stat.h> > > #include <ctype.h> >+#include <errno.h> > #include <signal.h> > #include <stddef.h> > #include <stdlib.h> >@@ -66,7 +67,7 @@ > #define CMD2_OBITS 0x08 > #define CMD2_UBITS 0x10 > >-static BITCMD *addcmd(BITCMD *, int, int, int, u_int); >+static BITCMD *addcmd(BITCMD *, char, mode_t, mode_t, mode_t); > static void compress_mode(BITCMD *); > #ifdef SETMODE_DEBUG > static void dumpmode(BITCMD *); >@@ -161,23 +162,24 @@ > saveset = newset; \ > endset = newset + (setlen - 2); \ > } \ >- set = addcmd(set, (a), (b), (c), (d)) >+ set = addcmd(set, (a), (b), (mode_t)(c), (d)) > > #define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) > > void * > setmode(const char *p) > { >- int perm, who; > char op, *ep; > BITCMD *set, *saveset, *endset; > sigset_t sigset, sigoset; >- mode_t mask; >- int equalopdone=0, permXbits, setlen; >+ mode_t mask, perm, permXbits, who; >+ int equalopdone=0, setlen; > long perml; > >- if (!*p) >+ if (!*p) { >+ errno = EINVAL; > return (NULL); >+ } > > /* > * Get a copy of the mask for the permissions that are mask relative. >@@ -206,10 +208,15 @@ > perml = strtol(p, &ep, 8); > if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) { > free(saveset); >+ /* >+ * This follows the OpenBSD behaviour. NetBSD returns >+ * EINVAL, except for the case when errno == ERANGE >+ * from strtol. >+ */ >+ errno = ERANGE; > return (NULL); > } >- perm = (mode_t)perml; >- ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); >+ ADDCMD('=', (STANDARD_BITS|S_ISTXT), perml, mask); > set->cmd = 0; > return (saveset); > } >@@ -241,6 +248,7 @@ > > getop: if ((op = *p++) != '+' && op != '-' && op != '=') { > free(saveset); >+ errno = EINVAL; > return (NULL); > } > if (op == '=') >@@ -253,12 +261,18 @@ > perm |= S_IRUSR|S_IRGRP|S_IROTH; > break; > case 's': >- /* If only "other" bits ignore set-id. */ >+ /* >+ * If specific bits were requested and >+ * only "other" bits ignore set-id. >+ */ > if (!who || who & ~S_IRWXO) > perm |= S_ISUID|S_ISGID; > break; > case 't': >- /* If only "other" bits ignore sticky. */ >+ /* >+ * If specific bits were requested and >+ * only "other" bits ignore sticky. >+ */ > if (!who || who & ~S_IRWXO) { > who |= S_ISTXT; > perm |= S_ISTXT; >@@ -333,7 +347,7 @@ > } > > static BITCMD * >-addcmd(BITCMD *set, int op, int who, int oparg, u_int mask) >+addcmd(BITCMD *set, char op, mode_t who, mode_t oparg, mode_t mask) > { > switch (op) { > case '=': >@@ -400,7 +414,8 @@ > compress_mode(BITCMD *set) > { > BITCMD *nset; >- int setbits, clrbits, Xbits, op; >+ char op; >+ mode_t setbits, clrbits, Xbits; > > for (nset = set;;) { > /* Copy over any 'u', 'g' and 'o' commands. */ >--- setmode.3 2009-07-12 01:42:34.938005607 +0300 >+++ setmode.3 2009-07-12 01:42:55.277377686 +0300 >@@ -97,9 +97,13 @@ > The > .Fn setmode > function >-may fail and set errno for any of the errors specified for the library >-routine >-.Xr malloc 3 . >+may fail and set errno to >+.Er ERANGE >+if an invalid octal value was specified, or to >+.Er EINVAL >+if an invalid mode value was specified. It may also fail and set errno >+to any of the errors specified for the library routine >+.Xr malloc 3 > .Sh SEE ALSO > .Xr chmod 1 , > .Xr stat 2 ,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 136669
: 97864 |
153280