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:
Kyle Evans 2020-10-01 19:56:38 +00:00
parent 2398cd1103
commit 320ef1bef0

View File

@ -67,8 +67,7 @@ __init_elf_aux_vector(void)
}
static pthread_once_t aux_once = PTHREAD_ONCE_INIT;
static int pagesize, osreldate, ncpus, bsdflags;
static size_t canary_len, pagesizes_len;
static int pagesize, osreldate, canary_len, ncpus, pagesizes_len, bsdflags;
static int hwcap_present, hwcap2_present;
static char *canary, *pagesizes, *execpath;
static void *ps_strings, *timekeep;
@ -246,7 +245,6 @@ int
_elf_aux_info(int aux, void *buf, int buflen)
{
int res;
size_t buflen_;
__init_elf_aux_vector();
if (__elf_aux_vector == NULL)
@ -255,12 +253,11 @@ _elf_aux_info(int aux, void *buf, int buflen)
if (buflen < 0)
return (EINVAL);
buflen_ = (size_t)buflen;
switch (aux) {
case AT_CANARY:
if (canary != NULL && canary_len >= buflen_) {
memcpy(buf, canary, buflen_);
if (canary != NULL && canary_len >= buflen) {
memcpy(buf, canary, buflen);
memset(canary, 0, canary_len);
canary = NULL;
res = 0;
@ -273,35 +270,36 @@ _elf_aux_info(int aux, void *buf, int buflen)
else if (buf == NULL)
res = EINVAL;
else {
if (strlcpy(buf, execpath, buflen_) >= buflen_)
if (strlcpy(buf, execpath, buflen) >=
(unsigned int)buflen)
res = EINVAL;
else
res = 0;
}
break;
case AT_HWCAP:
if (hwcap_present && buflen_ == sizeof(u_long)) {
if (hwcap_present && buflen == sizeof(u_long)) {
*(u_long *)buf = hwcap;
res = 0;
} else
res = ENOENT;
break;
case AT_HWCAP2:
if (hwcap2_present && buflen_ == sizeof(u_long)) {
if (hwcap2_present && buflen == sizeof(u_long)) {
*(u_long *)buf = hwcap2;
res = 0;
} else
res = ENOENT;
break;
case AT_PAGESIZES:
if (pagesizes != NULL && pagesizes_len >= buflen_) {
memcpy(buf, pagesizes, buflen_);
if (pagesizes != NULL && pagesizes_len >= buflen) {
memcpy(buf, pagesizes, buflen);
res = 0;
} else
res = ENOENT;
break;
case AT_PAGESZ:
if (buflen_ == sizeof(int)) {
if (buflen == sizeof(int)) {
if (pagesize != 0) {
*(int *)buf = pagesize;
res = 0;
@ -311,7 +309,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
res = EINVAL;
break;
case AT_OSRELDATE:
if (buflen_ == sizeof(int)) {
if (buflen == sizeof(int)) {
if (osreldate != 0) {
*(int *)buf = osreldate;
res = 0;
@ -321,7 +319,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
res = EINVAL;
break;
case AT_NCPUS:
if (buflen_ == sizeof(int)) {
if (buflen == sizeof(int)) {
if (ncpus != 0) {
*(int *)buf = ncpus;
res = 0;
@ -331,7 +329,7 @@ _elf_aux_info(int aux, void *buf, int buflen)
res = EINVAL;
break;
case AT_TIMEKEEP:
if (buflen_ == sizeof(void *)) {
if (buflen == sizeof(void *)) {
if (timekeep != NULL) {
*(void **)buf = timekeep;
res = 0;
@ -341,14 +339,14 @@ _elf_aux_info(int aux, void *buf, int buflen)
res = EINVAL;
break;
case AT_BSDFLAGS:
if (buflen_ == sizeof(int)) {
if (buflen == sizeof(int)) {
*(int *)buf = bsdflags;
res = 0;
} else
res = EINVAL;
break;
case AT_PS_STRINGS:
if (buflen_ == sizeof(void *)) {
if (buflen == sizeof(void *)) {
if (ps_strings != NULL) {
*(void **)buf = ps_strings;
res = 0;