Don't make a temporary copy of fixed sysctl strings.
This commit is contained in:
parent
d284902e11
commit
7ee53e6bf4
@ -1216,26 +1216,33 @@ int
|
|||||||
sysctl_handle_string(SYSCTL_HANDLER_ARGS)
|
sysctl_handle_string(SYSCTL_HANDLER_ARGS)
|
||||||
{
|
{
|
||||||
size_t outlen;
|
size_t outlen;
|
||||||
int error = 0;
|
int error = 0, ro_string = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A zero-length buffer indicates a fixed size read-only
|
* A zero-length buffer indicates a fixed size read-only
|
||||||
* string:
|
* string:
|
||||||
*/
|
*/
|
||||||
if (arg2 == 0)
|
if (arg2 == 0) {
|
||||||
arg2 = strlen((char *)arg1) + 1;
|
arg2 = strlen((char *)arg1) + 1;
|
||||||
|
ro_string = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (req->oldptr != NULL) {
|
if (req->oldptr != NULL) {
|
||||||
char *tmparg;
|
char *tmparg;
|
||||||
|
|
||||||
/* try to make a coherent snapshot of the string */
|
if (ro_string) {
|
||||||
tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
|
tmparg = arg1;
|
||||||
memcpy(tmparg, arg1, arg2);
|
} else {
|
||||||
|
/* try to make a coherent snapshot of the string */
|
||||||
|
tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
|
||||||
|
memcpy(tmparg, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
outlen = strnlen(tmparg, arg2 - 1) + 1;
|
outlen = strnlen(tmparg, arg2 - 1) + 1;
|
||||||
error = SYSCTL_OUT(req, tmparg, outlen);
|
error = SYSCTL_OUT(req, tmparg, outlen);
|
||||||
|
|
||||||
free(tmparg, M_SYSCTLTMP);
|
if (!ro_string)
|
||||||
|
free(tmparg, M_SYSCTLTMP);
|
||||||
} else {
|
} else {
|
||||||
outlen = strnlen((char *)arg1, arg2 - 1) + 1;
|
outlen = strnlen((char *)arg1, arg2 - 1) + 1;
|
||||||
error = SYSCTL_OUT(req, NULL, outlen);
|
error = SYSCTL_OUT(req, NULL, outlen);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user