Page MenuHomeFreeBSD

D57180.diff
No OneTemporary

D57180.diff

diff --git a/lib/libc/posix1e/acl_from_text.c b/lib/libc/posix1e/acl_from_text.c
--- a/lib/libc/posix1e/acl_from_text.c
+++ b/lib/libc/posix1e/acl_from_text.c
@@ -39,6 +39,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <inttypes.h>
#include <assert.h>
#include "acl_support.h"
@@ -263,6 +264,24 @@
return(NULL);
}
+/*
+ * Make sure the number given fits inside an uid_t or gid_t.
+ * Currently (2026-05-23) uid_t & gid_t is an uint32_t.
+ * Special case handle uid_t/gid_t numbers specified as negative numbers.
+ * Assumes that uid_t and gid_t are the same types.
+ */
+static int
+_invalid_uidgid(intmax_t v) {
+ if (v < 0) {
+ if ((-v) & ~(uintmax_t)((~(uid_t)0)>>1))
+ return (2); /* Underflow, does not fit into uid_t */
+ } else {
+ if (v & ~(uintmax_t)(~(uid_t)0))
+ return (1); /* Overflow, does not fit into uid_t */
+ }
+ return (0);
+}
+
/*
* Given a username/groupname from a text form of an ACL, return the uid/gid
* XXX NOT THREAD SAFE, RELIES ON GETPWNAM, GETGRNAM
@@ -274,19 +293,21 @@
{
struct group *g;
struct passwd *p;
- unsigned long l;
+ intmax_t v;
char *endp;
switch(tag) {
case ACL_USER:
p = getpwnam(name);
if (p == NULL) {
- l = strtoul(name, &endp, 0);
- if (*endp != '\0' || l != (unsigned long)(uid_t)l) {
- errno = EINVAL;
+ errno = 0;
+ v = strtoimax(name, &endp, 0);
+ if (name == endp || *endp != '\0' ||
+ errno == ERANGE || _invalid_uidgid(v) != 0) {
+ errno = EINVAL; /* No or invalid number */
return (-1);
}
- *id = (uid_t)l;
+ *id = v;
return (0);
}
*id = p->pw_uid;
@@ -295,12 +316,14 @@
case ACL_GROUP:
g = getgrnam(name);
if (g == NULL) {
- l = strtoul(name, &endp, 0);
- if (*endp != '\0' || l != (unsigned long)(gid_t)l) {
- errno = EINVAL;
+ errno = 0;
+ v = strtoimax(name, &endp, 0);
+ if (name == endp || *endp != '\0' ||
+ errno == ERANGE || _invalid_uidgid(v) != 0) {
+ errno = EINVAL; /* No or invalid number */
return (-1);
}
- *id = (gid_t)l;
+ *id = v;
return (0);
}
*id = g->gr_gid;

File Metadata

Mime Type
text/plain
Expires
Sat, Aug 1, 7:03 PM (2 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34810630
Default Alt Text
D57180.diff (2 KB)

Event Timeline