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

Lines changed: 8 additions & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy