auxv: partially revert r366207, cast buflen to unsigned int as needed
The warning generated pre-r366207 is actually a sign comparison warning: error: comparison of integers of different signs: 'unsigned long' and 'int' if (strlcpy(buf, execpath, buflen) >= buflen) Revert parts that affected other lines and just cast this to unsigned int. The buflen < 0 -> EINVAL has been kept despite no longer serving any purposes w.r.t. sign-extension because I do believe it's the right thing to do: "The provided buffer was not the right size for the requested item." The original warning is confirmed to still be gone with an: env WARNS=6 make WITHOUT_TESTS=yes. Reviewed by: asomers, kib X-MFC-With: r366207 Differential Revision: https://reviews.freebsd.org/D26631
This commit is contained in:
parent
2398cd1103
commit
320ef1bef0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366342
@ -67,8 +67,7 @@ __init_elf_aux_vector(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
|
static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
|
||||||
static int pagesize, osreldate, ncpus, bsdflags;
|
static int pagesize, osreldate, canary_len, ncpus, pagesizes_len, bsdflags;
|
||||||
static size_t canary_len, pagesizes_len;
|
|
||||||
static int hwcap_present, hwcap2_present;
|
static int hwcap_present, hwcap2_present;
|
||||||
static char *canary, *pagesizes, *execpath;
|
static char *canary, *pagesizes, *execpath;
|
||||||
static void *ps_strings, *timekeep;
|
static void *ps_strings, *timekeep;
|
||||||
@ -246,7 +245,6 @@ int
|
|||||||
_elf_aux_info(int aux, void *buf, int buflen)
|
_elf_aux_info(int aux, void *buf, int buflen)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
size_t buflen_;
|
|
||||||
|
|
||||||
__init_elf_aux_vector();
|
__init_elf_aux_vector();
|
||||||
if (__elf_aux_vector == NULL)
|
if (__elf_aux_vector == NULL)
|
||||||
@ -255,12 +253,11 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
|
|
||||||
if (buflen < 0)
|
if (buflen < 0)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
buflen_ = (size_t)buflen;
|
|
||||||
|
|
||||||
switch (aux) {
|
switch (aux) {
|
||||||
case AT_CANARY:
|
case AT_CANARY:
|
||||||
if (canary != NULL && canary_len >= buflen_) {
|
if (canary != NULL && canary_len >= buflen) {
|
||||||
memcpy(buf, canary, buflen_);
|
memcpy(buf, canary, buflen);
|
||||||
memset(canary, 0, canary_len);
|
memset(canary, 0, canary_len);
|
||||||
canary = NULL;
|
canary = NULL;
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -273,35 +270,36 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
else if (buf == NULL)
|
else if (buf == NULL)
|
||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
else {
|
else {
|
||||||
if (strlcpy(buf, execpath, buflen_) >= buflen_)
|
if (strlcpy(buf, execpath, buflen) >=
|
||||||
|
(unsigned int)buflen)
|
||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
else
|
else
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AT_HWCAP:
|
case AT_HWCAP:
|
||||||
if (hwcap_present && buflen_ == sizeof(u_long)) {
|
if (hwcap_present && buflen == sizeof(u_long)) {
|
||||||
*(u_long *)buf = hwcap;
|
*(u_long *)buf = hwcap;
|
||||||
res = 0;
|
res = 0;
|
||||||
} else
|
} else
|
||||||
res = ENOENT;
|
res = ENOENT;
|
||||||
break;
|
break;
|
||||||
case AT_HWCAP2:
|
case AT_HWCAP2:
|
||||||
if (hwcap2_present && buflen_ == sizeof(u_long)) {
|
if (hwcap2_present && buflen == sizeof(u_long)) {
|
||||||
*(u_long *)buf = hwcap2;
|
*(u_long *)buf = hwcap2;
|
||||||
res = 0;
|
res = 0;
|
||||||
} else
|
} else
|
||||||
res = ENOENT;
|
res = ENOENT;
|
||||||
break;
|
break;
|
||||||
case AT_PAGESIZES:
|
case AT_PAGESIZES:
|
||||||
if (pagesizes != NULL && pagesizes_len >= buflen_) {
|
if (pagesizes != NULL && pagesizes_len >= buflen) {
|
||||||
memcpy(buf, pagesizes, buflen_);
|
memcpy(buf, pagesizes, buflen);
|
||||||
res = 0;
|
res = 0;
|
||||||
} else
|
} else
|
||||||
res = ENOENT;
|
res = ENOENT;
|
||||||
break;
|
break;
|
||||||
case AT_PAGESZ:
|
case AT_PAGESZ:
|
||||||
if (buflen_ == sizeof(int)) {
|
if (buflen == sizeof(int)) {
|
||||||
if (pagesize != 0) {
|
if (pagesize != 0) {
|
||||||
*(int *)buf = pagesize;
|
*(int *)buf = pagesize;
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -311,7 +309,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
break;
|
break;
|
||||||
case AT_OSRELDATE:
|
case AT_OSRELDATE:
|
||||||
if (buflen_ == sizeof(int)) {
|
if (buflen == sizeof(int)) {
|
||||||
if (osreldate != 0) {
|
if (osreldate != 0) {
|
||||||
*(int *)buf = osreldate;
|
*(int *)buf = osreldate;
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -321,7 +319,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
break;
|
break;
|
||||||
case AT_NCPUS:
|
case AT_NCPUS:
|
||||||
if (buflen_ == sizeof(int)) {
|
if (buflen == sizeof(int)) {
|
||||||
if (ncpus != 0) {
|
if (ncpus != 0) {
|
||||||
*(int *)buf = ncpus;
|
*(int *)buf = ncpus;
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -331,7 +329,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
break;
|
break;
|
||||||
case AT_TIMEKEEP:
|
case AT_TIMEKEEP:
|
||||||
if (buflen_ == sizeof(void *)) {
|
if (buflen == sizeof(void *)) {
|
||||||
if (timekeep != NULL) {
|
if (timekeep != NULL) {
|
||||||
*(void **)buf = timekeep;
|
*(void **)buf = timekeep;
|
||||||
res = 0;
|
res = 0;
|
||||||
@ -341,14 +339,14 @@ _elf_aux_info(int aux, void *buf, int buflen)
|
|||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
break;
|
break;
|
||||||
case AT_BSDFLAGS:
|
case AT_BSDFLAGS:
|
||||||
if (buflen_ == sizeof(int)) {
|
if (buflen == sizeof(int)) {
|
||||||
*(int *)buf = bsdflags;
|
*(int *)buf = bsdflags;
|
||||||
res = 0;
|
res = 0;
|
||||||
} else
|
} else
|
||||||
res = EINVAL;
|
res = EINVAL;
|
||||||
break;
|
break;
|
||||||
case AT_PS_STRINGS:
|
case AT_PS_STRINGS:
|
||||||
if (buflen_ == sizeof(void *)) {
|
if (buflen == sizeof(void *)) {
|
||||||
if (ps_strings != NULL) {
|
if (ps_strings != NULL) {
|
||||||
*(void **)buf = ps_strings;
|
*(void **)buf = ps_strings;
|
||||||
res = 0;
|
res = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user