Reserve room for the terminating NUL when setting or getting kernel

environment variables. KENV_MNAMELEN and KENV_MVALLEN doesn't include
space for the terminating NUL.
This commit is contained in:
jh 2012-08-14 19:16:30 +00:00
parent 0c96728586
commit 6e556a5317

View File

@ -143,9 +143,9 @@ sys_kenv(td, uap)
break;
}
name = malloc(KENV_MNAMELEN, M_TEMP, M_WAITOK);
name = malloc(KENV_MNAMELEN + 1, M_TEMP, M_WAITOK);
error = copyinstr(uap->name, name, KENV_MNAMELEN, NULL);
error = copyinstr(uap->name, name, KENV_MNAMELEN + 1, NULL);
if (error)
goto done;
@ -176,8 +176,8 @@ sys_kenv(td, uap)
error = EINVAL;
goto done;
}
if (len > KENV_MVALLEN)
len = KENV_MVALLEN;
if (len > KENV_MVALLEN + 1)
len = KENV_MVALLEN + 1;
value = malloc(len, M_TEMP, M_WAITOK);
error = copyinstr(uap->value, value, len, NULL);
if (error) {
@ -389,10 +389,10 @@ setenv(const char *name, const char *value)
KENV_CHECK;
namelen = strlen(name) + 1;
if (namelen > KENV_MNAMELEN)
if (namelen > KENV_MNAMELEN + 1)
return (-1);
vallen = strlen(value) + 1;
if (vallen > KENV_MVALLEN)
if (vallen > KENV_MVALLEN + 1)
return (-1);
buf = malloc(namelen + vallen, M_KENV, M_WAITOK);
sprintf(buf, "%s=%s", name, value);