]> granicus.if.org Git - linux-pam/commitdiff
libpam_misc: fix an inconsistency in handling memory allocation errors
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 22 Jan 2014 02:34:03 +0000 (02:34 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 22 Jan 2014 22:54:12 +0000 (22:54 +0000)
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

index 3f74eeae7c0eaebb748d09d12538b6112af8abc4..be53f3433929cefd01277e9471059ccc09b8e5a6 100644 (file)
@@ -210,8 +210,12 @@ 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 */