Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6afe200

Browse files
committed
chkpass: check for NULL return value from crypt()
Report from Jozef Mlich using Coverity
1 parent 85317e8 commit 6afe200

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

contrib/chkpass/chkpass.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ chkpass_in(PG_FUNCTION_ARGS)
7070
char *str = PG_GETARG_CSTRING(0);
7171
chkpass *result;
7272
char mysalt[4];
73+
char *crypt_output;
7374
static char salt_chars[] =
7475
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
7576

@@ -92,7 +93,13 @@ chkpass_in(PG_FUNCTION_ARGS)
9293
mysalt[1] = salt_chars[random() & 0x3f];
9394
mysalt[2] = 0; /* technically the terminator is not necessary
9495
* but I like to play safe */
95-
strcpy(result->password, crypt(str, mysalt));
96+
97+
if ((crypt_output = crypt(str, mysalt)) == NULL)
98+
ereport(ERROR,
99+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
100+
errmsg("crypt() failed")));
101+
strcpy(result->password, crypt_output);
102+
96103
PG_RETURN_POINTER(result);
97104
}
98105

0 commit comments

Comments
 (0)