Skip to content

Commit 4714984

Browse files
author
Neil Conway
committed
Fix a theoretical memory leak in pg_password_sendauth(). If the first
malloc() succeeded but the second failed, the buffer allocated by the first malloc() would be leaked. Fix this by allocating both buffers via a single malloc(), as suggested by Tom. Per Coverity static analysis performed by EnterpriseDB.
1 parent 401de9c commit 4714984

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.102 2005/06/27 02:04:26 neilc Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.103 2005/06/30 01:59:20 neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -407,27 +407,27 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
407407
{
408408
char *crypt_pwd2;
409409

410-
if (!(crypt_pwd = malloc(MD5_PASSWD_LEN + 1)) ||
411-
!(crypt_pwd2 = malloc(MD5_PASSWD_LEN + 1)))
410+
/* Allocate enough space for two MD5 hashes */
411+
crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1));
412+
if (!crypt_pwd)
412413
{
413414
fprintf(stderr, libpq_gettext("out of memory\n"));
414415
return STATUS_ERROR;
415416
}
417+
418+
crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1;
416419
if (!EncryptMD5(password, conn->pguser,
417420
strlen(conn->pguser), crypt_pwd2))
418421
{
419422
free(crypt_pwd);
420-
free(crypt_pwd2);
421423
return STATUS_ERROR;
422424
}
423425
if (!EncryptMD5(crypt_pwd2 + strlen("md5"), conn->md5Salt,
424426
sizeof(conn->md5Salt), crypt_pwd))
425427
{
426428
free(crypt_pwd);
427-
free(crypt_pwd2);
428429
return STATUS_ERROR;
429430
}
430-
free(crypt_pwd2);
431431
break;
432432
}
433433
case AUTH_REQ_CRYPT:

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