]> granicus.if.org Git - postgresql/commitdiff
chkpass: check for NULL return value from crypt()
authorBruce Momjian <bruce@momjian.us>
Sat, 1 Feb 2014 01:19:53 +0000 (20:19 -0500)
committerBruce Momjian <bruce@momjian.us>
Sat, 1 Feb 2014 01:19:53 +0000 (20:19 -0500)
Report from Jozef Mlich using Coverity

contrib/chkpass/chkpass.c

index 0c9fec0e676fc1140a2b4338c8df0a904b551d3f..dc66075f9886d4b14a3b639224833f9cb5b73b45 100644 (file)
@@ -70,6 +70,7 @@ chkpass_in(PG_FUNCTION_ARGS)
        char       *str = PG_GETARG_CSTRING(0);
        chkpass    *result;
        char            mysalt[4];
+       char       *crypt_output;
        static char salt_chars[] =
        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 
@@ -92,7 +93,13 @@ chkpass_in(PG_FUNCTION_ARGS)
        mysalt[1] = salt_chars[random() & 0x3f];
        mysalt[2] = 0;                          /* technically the terminator is not necessary
                                                                 * but I like to play safe */
-       strcpy(result->password, crypt(str, mysalt));
+
+       if ((crypt_output = crypt(str, mysalt)) == NULL)
+               ereport(ERROR,
+                               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+                                errmsg("crypt() failed")));
+       strcpy(result->password, crypt_output);
+
        PG_RETURN_POINTER(result);
 }