Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4714984

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 thefirst malloc() would be leaked. Fix this by allocating both buffersvia a single malloc(), as suggested by Tom.Per Coverity static analysis performed by EnterpriseDB.
1 parent401de9c commit4714984

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
returnSTATUS_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
returnSTATUS_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
returnSTATUS_ERROR;
429430
}
430-
free(crypt_pwd2);
431431
break;
432432
}
433433
caseAUTH_REQ_CRYPT:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp