FreeBSD Bugzilla – Attachment 153280 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]
Patch based on NetBSD
libc-setmode.diff (text/plain), 2.67 KB, created by
Pedro F. Giffuni
on 2015-02-21 16:59:41 UTC
(
hide
)
Description:
Patch based on NetBSD
Filename:
MIME Type:
Creator:
Pedro F. Giffuni
Created:
2015-02-21 16:59:41 UTC
Size:
2.67 KB
patch
obsolete
>Index: lib/libc/gen/setmode.c >=================================================================== >--- lib/libc/gen/setmode.c (revision 279068) >+++ lib/libc/gen/setmode.c (working copy) >@@ -41,9 +41,11 @@ > #include <sys/stat.h> > > #include <ctype.h> >+#include <errno.h> > #include <signal.h> > #include <stddef.h> > #include <stdlib.h> >+#include <limits.h> > #include <unistd.h> > > #ifdef SETMODE_DEBUG >@@ -66,7 +68,7 @@ > #define CMD2_OBITS 0x08 > #define CMD2_UBITS 0x10 > >-static BITCMD *addcmd(BITCMD *, int, int, int, u_int); >+static BITCMD *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t); > static void compress_mode(BITCMD *); > #ifdef SETMODE_DEBUG > static void dumpmode(BITCMD *); >@@ -151,17 +153,13 @@ > BITCMD *newset; \ > setlen += SET_LEN_INCR; \ > newset = realloc(saveset, sizeof(BITCMD) * setlen); \ >- if (!newset) { \ >- if (saveset) \ >- free(saveset); \ >- saveset = NULL; \ >- return (NULL); \ >- } \ >+ if (newset == NULL) \ >+ goto out; \ > set = newset + (set - saveset); \ > saveset = newset; \ > endset = newset + (setlen - 2); \ > } \ >- set = addcmd(set, (a), (b), (c), (d)) >+ set = addcmd(set, (mode_t)(a), (mode_t)(b), (mode_t)(c), (d)) > > #define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) > >@@ -168,13 +166,14 @@ > void * > setmode(const char *p) > { >- int perm, who; >+ int serrno; > 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; > long perml; >+ int equalopdone = 0; /* pacify gcc */ >+ int setlen; > > if (!*p) > return (NULL); >@@ -203,11 +202,18 @@ > * or illegal bits. > */ > if (isdigit((unsigned char)*p)) { >+ errno = 0; > perml = strtol(p, &ep, 8); >- if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) { >- free(saveset); >- return (NULL); >+ if (*ep) { >+ errno = EINVAL; >+ goto out; > } >+ if (errno == ERANGE && (perml == LONG_MAX || perml == LONG_MIN)) >+ goto out; >+ if (perml & ~(STANDARD_BITS|S_ISTXT)) { >+ errno = EINVAL; >+ goto out; >+ } > perm = (mode_t)perml; > ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask); > set->cmd = 0; >@@ -240,8 +246,8 @@ > } > > getop: if ((op = *p++) != '+' && op != '-' && op != '=') { >- free(saveset); >- return (NULL); >+ errno = EINVAL; >+ goto out; > } > if (op == '=') > equalopdone = 0; >@@ -330,10 +336,15 @@ > dumpmode(saveset); > #endif > return (saveset); >+out: >+ serrno = errno; >+ free(saveset); >+ errno = serrno; >+ return NULL; > } > > static BITCMD * >-addcmd(BITCMD *set, int op, int who, int oparg, u_int mask) >+addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask) > { > switch (op) { > case '=':
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