Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144359281
D47614.id146547.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D47614.id146547.diff
View Options
diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c
--- a/sys/security/mac_do/mac_do.c
+++ b/sys/security/mac_do/mac_do.c
@@ -8,6 +8,7 @@
#include <sys/malloc.h>
#include <sys/jail.h>
#include <sys/kernel.h>
+#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mount.h>
@@ -85,6 +86,24 @@
return (rules);
}
+/*
+ * String to non-negative int.
+ *
+ * Returns minus an error (EINVAL or EOVERFLOW) in case of failure.
+ */
+static int
+strtonni(const char *const restrict s, char **const restrict endptr, int base)
+{
+ const long l = strtol(s, endptr, base);
+
+ if (l < 0)
+ return (-EINVAL);
+ else if (l == LONG_MAX || l > INT_MAX)
+ return (-EOVERFLOW);
+
+ return ((int)l);
+}
+
static int
parse_rule_element(char *element, struct rule **rule)
{
@@ -109,7 +128,10 @@
if (from_id == NULL || *from_id == '\0')
goto einval;
- new->from_id = strtol(from_id, &p, 10);
+ new->from_id = strtonni(from_id, &p, 10);
+ if (*p != '\0' || new->from_id < 0)
+ goto einval;
+
if (*p != '\0')
goto einval;
@@ -121,8 +143,8 @@
new->to_type = RULE_ANY;
else {
new->to_type = RULE_UID;
- new->to_id = strtol(to, &p, 10);
- if (*p != '\0')
+ new->to_id = strtonni(to, &p, 10);
+ if (*p != '\0' || new->to_id < 0)
goto einval;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 9, 1:09 AM (8 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28518931
Default Alt Text
D47614.id146547.diff (1 KB)
Attached To
Mode
D47614: MAC/do: Better parsing for IDs (strtoui_strict())
Attached
Detach File
Event Timeline
Log In to Comment