roken: Move dead code in rk_getauxval() into #ifdefs

This commit is contained in:
Nicolas Williams
2023-01-04 16:03:35 -06:00
parent 2d5880734b
commit 1d5435043a
2 changed files with 19 additions and 12 deletions

View File

@@ -159,7 +159,6 @@ rk_getprocauxval(unsigned long type)
ROKEN_LIB_FUNCTION unsigned long ROKEN_LIB_CALL ROKEN_LIB_FUNCTION unsigned long ROKEN_LIB_CALL
rk_getauxval(unsigned long type) rk_getauxval(unsigned long type)
{ {
const auxv_t *a;
#ifdef HAVE_GETAUXVAL #ifdef HAVE_GETAUXVAL
#ifdef GETAUXVAL_SETS_ERRNO #ifdef GETAUXVAL_SETS_ERRNO
if (rk_injected_auxv) if (rk_injected_auxv)
@@ -169,6 +168,7 @@ rk_getauxval(unsigned long type)
unsigned long ret; unsigned long ret;
unsigned long ret2; unsigned long ret2;
static int getauxval_sets_errno = -1; static int getauxval_sets_errno = -1;
const auxv_t *a;
int save_errno = errno; int save_errno = errno;
if (rk_injected_auxv) if (rk_injected_auxv)
@@ -212,13 +212,21 @@ rk_getauxval(unsigned long type)
getauxval_sets_errno = 0; getauxval_sets_errno = 0;
errno = save_errno; errno = save_errno;
#endif
#endif
if ((a = rk_getauxv(type)) == NULL) { if ((a = rk_getauxv(type)) == NULL) {
errno = ENOENT; errno = ENOENT;
return 0; return 0;
} }
return a->a_un.a_val; return a->a_un.a_val;
#endif
#else
const auxv_t *a;
if ((a = rk_getauxv(type)) == NULL) {
errno = ENOENT;
return 0;
}
return a->a_un.a_val;
#endif
} }
/** /**

View File

@@ -47,20 +47,19 @@ static void
check_secure_getenv(char **env) check_secure_getenv(char **env)
{ {
size_t i; size_t i;
char *v; char *v, *p;
for (i = 0; env[i] != NULL; i++) { for (i = 0; env[i] != NULL; i++) {
if (strchr(env[i], '=') == NULL)
continue;
if ((v = strdup(env[i])) == NULL) if ((v = strdup(env[i])) == NULL)
err(1, "could not allocate copy of %s", env[i]); err(1, "could not allocate copy of %s", env[i]);
*strchr(v, '=') = '\0'; if ((p = strchr(v, '='))) {
*p = '\0';
if (issuid() && rk_secure_getenv(v) != NULL) if (issuid() && rk_secure_getenv(v) != NULL)
err(1, "rk_secure_getenv() returned non-NULL when issuid()!"); err(1, "rk_secure_getenv() returned non-NULL when issuid()!");
if (!issuid() && rk_secure_getenv(v) == NULL) if (!issuid() && rk_secure_getenv(v) == NULL)
err(1, "rk_secure_getenv() returned NULL when !issuid()"); err(1, "rk_secure_getenv() returned NULL when !issuid()");
}
free(v); free(v);
return;
} }
} }