When misc_conv fails to allocate memory for pam_response array, it returns PAM_CONV_ERR. However, when read_string fails to allocate memory for a response string, it loses the response string and silently ignores the error, with net result as if EOF has been read.
* libpam_misc/misc_conv.c (read_string): Use strdup instead of x_strdup, the latter is of no benefit in this case. Do not ignore potential memory allocation errors returned by strdup, forward them to misc_conv. --- libpam_misc/misc_conv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libpam_misc/misc_conv.c b/libpam_misc/misc_conv.c index 3f74eea..be53f34 100644 --- a/libpam_misc/misc_conv.c +++ b/libpam_misc/misc_conv.c @@ -210,25 +210,29 @@ static int read_string(int echo, const char *prompt, char **retstr) } line[nc] = '\0'; } - *retstr = x_strdup(line); + *retstr = strdup(line); _pam_overwrite(line); + if (!*retstr) { + D(("no memory for response string")); + nc = -1; + }
goto cleanexit; /* return malloc()ed string */
} else if (nc == 0) { /* Ctrl-D */ D(("user did not want to type anything"));
*retstr = NULL; if (echo) { fprintf(stderr, "\n"); } goto cleanexit; /* return malloc()ed "" */ } else if (nc == -1) { /* Don't loop forever if read() returns -1. */ D(("error reading input from the user: %m")); if (echo) { fprintf(stderr, "\n"); } *retstr = NULL; goto cleanexit; /* return NULL */ }