sysctl_handle_string: do not malloc when SYSCTL_IN cannot fault
In particular, this avoids malloc(9) calls when from early tunable handling, with no working malloc yet. Reported and tested by: mav Sponsored by: The FreeBSD Foundation MFC after: 1 week
This commit is contained in:
parent
578c26f31c
commit
4342ba184c
@ -1785,6 +1785,15 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
|
||||
sx_xlock(&sysctlstringlock);
|
||||
((char *)arg1)[0] = '\0';
|
||||
sx_xunlock(&sysctlstringlock);
|
||||
} else if (req->newfunc == sysctl_new_kernel) {
|
||||
arg2 = req->newlen - req->newidx;
|
||||
sx_xlock(&sysctlstringlock);
|
||||
error = SYSCTL_IN(req, arg1, arg2);
|
||||
if (error == 0) {
|
||||
((char *)arg1)[arg2] = '\0';
|
||||
req->newidx += arg2;
|
||||
}
|
||||
sx_xunlock(&sysctlstringlock);
|
||||
} else {
|
||||
arg2 = req->newlen - req->newidx;
|
||||
tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
|
||||
|
Loading…
Reference in New Issue
Block a user