From 7187c19c839b44f70eb771e24a6aad39f1e0aab8 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 14 Jul 2015 14:00:18 -0600 Subject: [PATCH] Add warning if calloc() fails. Add debugging for other unexpected errors. --- plugins/sudoers/auth/pam.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/sudoers/auth/pam.c b/plugins/sudoers/auth/pam.c index 571dbf824..5e96959cd 100644 --- a/plugins/sudoers/auth/pam.c +++ b/plugins/sudoers/auth/pam.c @@ -320,11 +320,16 @@ converse(int num_msg, PAM_CONST struct pam_message **msg, int ret = PAM_SUCCESS; debug_decl(converse, SUDOERS_DEBUG_AUTH) - if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG) + if (num_msg <= 0 || num_msg > PAM_MAX_NUM_MSG) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "invalid number of PAM messages: %d", num_msg); debug_return_int(PAM_CONV_ERR); + } - if ((*response = calloc(num_msg, sizeof(struct pam_response))) == NULL) + if ((*response = calloc(num_msg, sizeof(struct pam_response))) == NULL) { + sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); debug_return_int(PAM_BUF_ERR); + } for (pr = *response, pm = *msg, n = num_msg; n--; pr++, pm++) { type = SUDO_CONV_PROMPT_ECHO_OFF; @@ -364,6 +369,8 @@ converse(int num_msg, PAM_CONST struct pam_message **msg, goto done; } if (strlen(pass) >= PAM_MAX_RESP_SIZE) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "password longer than %d", PAM_MAX_RESP_SIZE); ret = PAM_CONV_ERR; goto done; } -- 2.40.0