From 48459292ff78980a26f19a0553ca659fe47fee9f Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 1 Aug 2017 13:45:32 -0600 Subject: [PATCH] Don't send email about an unresolvable host name if fqdn is enabled and the user specified the run host via the -h flag. --- plugins/sudoers/sudoers.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 132113672..7b2fe9cd8 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -1100,8 +1100,9 @@ cb_fqdn(const union sudo_defs_val *sd_un) /* Next resolve user_runhost, setting user_runhost and user_srunhost. */ lhost = shost = NULL; if (remote) { - /* Failure checked below. */ - (void)resolve_host(user_runhost, &lhost, &shost); + if (!resolve_host(user_runhost, &lhost, &shost)) { + sudo_warnx(U_("unable to resolve host %s"), user_runhost); + } } else { /* Not remote, just use user_host. */ if ((lhost = strdup(user_host)) != NULL) { @@ -1110,19 +1111,21 @@ cb_fqdn(const union sudo_defs_val *sd_un) else shost = lhost; } + if (lhost == NULL || shost == NULL) { + free(lhost); + if (lhost != shost) + free(shost); + sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + debug_return_bool(false); + } } - if (lhost == NULL || shost == NULL) { - free(lhost); - free(shost); - log_warning(SLOG_SEND_MAIL|SLOG_RAW_MSG, - N_("unable to resolve host %s"), user_runhost); - debug_return_bool(false); + if (lhost != NULL && shost != NULL) { + if (user_srunhost != user_runhost) + free(user_srunhost); + free(user_runhost); + user_runhost = lhost; + user_srunhost = shost; } - if (user_srunhost != user_runhost) - free(user_srunhost); - free(user_runhost); - user_runhost = lhost; - user_srunhost = shost; sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, "host %s, shost %s, runhost %s, srunhost %s", -- 2.40.0