From 037ce3fa7f4da8219eed529e7a7e3d11240c5211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 10 Dec 2003 16:40:10 +0000 Subject: [PATCH] Fix same old bug in sample conversation function. --- en_US.ISO8859-1/articles/pam/converse.c | 26 +++++++++++++++---------- fr_FR.ISO8859-1/articles/pam/converse.c | 26 +++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/en_US.ISO8859-1/articles/pam/converse.c b/en_US.ISO8859-1/articles/pam/converse.c index 512fe81de8..2f8297dc0f 100644 --- a/en_US.ISO8859-1/articles/pam/converse.c +++ b/en_US.ISO8859-1/articles/pam/converse.c @@ -45,29 +45,30 @@ int converse(int n, const struct pam_message **msg, struct pam_response **resp, void *data) { + struct pam_response *aresp; char buf[PAM_MAX_RESP_SIZE]; int i; data = data; if (n <= 0 || n > PAM_MAX_NUM_MSG) return (PAM_CONV_ERR); - if ((*resp = calloc(n, sizeof **resp)) == NULL) + if ((aresp = calloc(n, sizeof *aresp)) == NULL) return (PAM_BUF_ERR); for (i = 0; i < n; ++i) { - resp[i]->resp_retcode = 0; - resp[i]->resp = NULL; + aresp[i].resp_retcode = 0; + aresp[i].resp = NULL; switch (msg[i]->msg_style) { case PAM_PROMPT_ECHO_OFF: - resp[i]->resp = strdup(getpass(msg[i]->msg)); - if (resp[i]->resp == NULL) + aresp[i].resp = strdup(getpass(msg[i]->msg)); + if (aresp[i].resp == NULL) goto fail; break; case PAM_PROMPT_ECHO_ON: fputs(msg[i]->msg, stderr); if (fgets(buf, sizeof buf, stdin) == NULL) goto fail; - resp[i]->resp = strdup(buf); - if (resp[i]->resp == NULL) + aresp[i].resp = strdup(buf); + if (aresp[i].resp == NULL) goto fail; break; case PAM_ERROR_MSG: @@ -86,11 +87,16 @@ converse(int n, const struct pam_message **msg, goto fail; } } + *resp = aresp; return (PAM_SUCCESS); fail: - while (i) - free(resp[--i]); - free(*resp); + for (i = 0; i < n; ++i) { + if (aresp[i].resp != NULL) { + memset(aresp[i].resp, 0, strlen(aresp[i].resp)); + free(aresp[i].resp); + } + } + memset(aresp, 0, n * sizeof *aresp); *resp = NULL; return (PAM_CONV_ERR); } diff --git a/fr_FR.ISO8859-1/articles/pam/converse.c b/fr_FR.ISO8859-1/articles/pam/converse.c index 512fe81de8..2f8297dc0f 100644 --- a/fr_FR.ISO8859-1/articles/pam/converse.c +++ b/fr_FR.ISO8859-1/articles/pam/converse.c @@ -45,29 +45,30 @@ int converse(int n, const struct pam_message **msg, struct pam_response **resp, void *data) { + struct pam_response *aresp; char buf[PAM_MAX_RESP_SIZE]; int i; data = data; if (n <= 0 || n > PAM_MAX_NUM_MSG) return (PAM_CONV_ERR); - if ((*resp = calloc(n, sizeof **resp)) == NULL) + if ((aresp = calloc(n, sizeof *aresp)) == NULL) return (PAM_BUF_ERR); for (i = 0; i < n; ++i) { - resp[i]->resp_retcode = 0; - resp[i]->resp = NULL; + aresp[i].resp_retcode = 0; + aresp[i].resp = NULL; switch (msg[i]->msg_style) { case PAM_PROMPT_ECHO_OFF: - resp[i]->resp = strdup(getpass(msg[i]->msg)); - if (resp[i]->resp == NULL) + aresp[i].resp = strdup(getpass(msg[i]->msg)); + if (aresp[i].resp == NULL) goto fail; break; case PAM_PROMPT_ECHO_ON: fputs(msg[i]->msg, stderr); if (fgets(buf, sizeof buf, stdin) == NULL) goto fail; - resp[i]->resp = strdup(buf); - if (resp[i]->resp == NULL) + aresp[i].resp = strdup(buf); + if (aresp[i].resp == NULL) goto fail; break; case PAM_ERROR_MSG: @@ -86,11 +87,16 @@ converse(int n, const struct pam_message **msg, goto fail; } } + *resp = aresp; return (PAM_SUCCESS); fail: - while (i) - free(resp[--i]); - free(*resp); + for (i = 0; i < n; ++i) { + if (aresp[i].resp != NULL) { + memset(aresp[i].resp, 0, strlen(aresp[i].resp)); + free(aresp[i].resp); + } + } + memset(aresp, 0, n * sizeof *aresp); *resp = NULL; return (PAM_CONV_ERR); }