From ae00eb719ecbb10c1b9d9f46fa15147cf022aaa7 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 11 Nov 2014 15:31:16 -0700 Subject: [PATCH] Do not call sudo_warnx() on invalid value from the env hook functions as the printf() family may call getenv() for locale reasons. --- src/hooks.c | 52 ++++++++-------------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/src/hooks.c b/src/hooks.c index 7f4932568..1d3a3bcb4 100644 --- a/src/hooks.c +++ b/src/hooks.c @@ -74,18 +74,9 @@ process_hooks_setenv(const char *name, const char *value, int overwrite) /* First process the hooks. */ SLIST_FOREACH(hook, &sudo_hook_setenv_list, entries) { rc = hook->u.setenv_fn(name, value, overwrite, hook->closure); - switch (rc) { - case SUDO_HOOK_RET_NEXT: - break; - case SUDO_HOOK_RET_ERROR: - case SUDO_HOOK_RET_STOP: - goto done; - default: - sudo_warnx_nodebug("invalid setenv hook return value: %d", rc); - break; - } + if (rc == SUDO_HOOK_RET_STOP || SUDO_HOOK_RET_ERROR) + break; } -done: return rc; } @@ -99,18 +90,9 @@ process_hooks_putenv(char *string) /* First process the hooks. */ SLIST_FOREACH(hook, &sudo_hook_putenv_list, entries) { rc = hook->u.putenv_fn(string, hook->closure); - switch (rc) { - case SUDO_HOOK_RET_NEXT: - break; - case SUDO_HOOK_RET_ERROR: - case SUDO_HOOK_RET_STOP: - goto done; - default: - sudo_warnx_nodebug("invalid putenv hook return value: %d", rc); - break; - } + if (rc == SUDO_HOOK_RET_STOP || SUDO_HOOK_RET_ERROR) + break; } -done: return rc; } @@ -125,18 +107,9 @@ process_hooks_getenv(const char *name, char **value) /* First process the hooks. */ SLIST_FOREACH(hook, &sudo_hook_getenv_list, entries) { rc = hook->u.getenv_fn(name, &val, hook->closure); - switch (rc) { - case SUDO_HOOK_RET_NEXT: - break; - case SUDO_HOOK_RET_ERROR: - case SUDO_HOOK_RET_STOP: - goto done; - default: - sudo_warnx_nodebug("invalid getenv hook return value: %d", rc); - break; - } + if (rc == SUDO_HOOK_RET_STOP || SUDO_HOOK_RET_ERROR) + break; } -done: if (val != NULL) *value = val; return rc; @@ -152,18 +125,9 @@ process_hooks_unsetenv(const char *name) /* First process the hooks. */ SLIST_FOREACH(hook, &sudo_hook_unsetenv_list, entries) { rc = hook->u.unsetenv_fn(name, hook->closure); - switch (rc) { - case SUDO_HOOK_RET_NEXT: - break; - case SUDO_HOOK_RET_ERROR: - case SUDO_HOOK_RET_STOP: - goto done; - default: - sudo_warnx_nodebug("invalid unsetenv hook return value: %d", rc); - break; - } + if (rc == SUDO_HOOK_RET_STOP || SUDO_HOOK_RET_ERROR) + break; } -done: return rc; } -- 2.40.0