aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/gen/sysctl.c28
-rw-r--r--sys/kern/kern_mib.c7
2 files changed, 23 insertions, 12 deletions
diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c
index ac6140013038..6015d68e8c60 100644
--- a/lib/libc/gen/sysctl.c
+++ b/lib/libc/gen/sysctl.c
@@ -68,14 +68,14 @@ sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
if (retval || name[0] != CTL_USER)
return (retval);
- if (newp != NULL) {
- errno = EPERM;
- return (-1);
- }
if (namelen != 2) {
errno = EINVAL;
return (-1);
}
+ if (newp != NULL && name[1] != USER_LOCALBASE) {
+ errno = EPERM;
+ return (-1);
+ }
switch (name[1]) {
case USER_CS_PATH:
@@ -88,13 +88,21 @@ sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH));
return (0);
case USER_LOCALBASE:
- if (oldp != NULL && orig_oldlen < sizeof(_PATH_LOCALBASE)) {
- errno = ENOMEM;
- return (-1);
+ if (oldlenp != NULL) {
+ if (oldp == NULL) {
+ if (*oldlenp == 1)
+ *oldlenp = sizeof(_PATH_LOCALBASE);
+ } else {
+ if (*oldlenp != 1)
+ return (retval);
+ if (orig_oldlen < sizeof(_PATH_LOCALBASE)) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ *oldlenp = sizeof(_PATH_LOCALBASE);
+ memmove(oldp, _PATH_LOCALBASE, sizeof(_PATH_LOCALBASE));
+ }
}
- *oldlenp = sizeof(_PATH_LOCALBASE);
- if (oldp != NULL)
- memmove(oldp, _PATH_LOCALBASE, sizeof(_PATH_LOCALBASE));
return (0);
}
diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c
index 47923da113d3..07db75ae753d 100644
--- a/sys/kern/kern_mib.c
+++ b/sys/kern/kern_mib.c
@@ -652,8 +652,11 @@ SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time");
SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names");
-SYSCTL_STRING(_user, USER_LOCALBASE, localbase, CTLFLAG_RD,
- "", 0, "Prefix used to install and locate add-on packages");
+
+static char localbase[MAXPATHLEN] = "";
+
+SYSCTL_STRING(_user, USER_LOCALBASE, localbase, CTLFLAG_RWTUN,
+ localbase, sizeof(localbase), "Prefix used to install and locate add-on packages");
#include <sys/vnode.h>
SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,