Skip to content

Commit 8130cbc

Browse files
committed
Clean up md5.c to make it clearer that it is a frontend-and-backend
module. Don't rely on backend palloc semantics; in fact, best to not use palloc at all, rather than #define'ing it to malloc, because that just encourages errors of omission. Bug spotted by Volkan YAZICI, but I went further than he did to fix it.
1 parent a5bd1d3 commit 8130cbc

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/backend/libpq/md5.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.30 2005/10/17 16:24:19 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.31 2005/10/20 13:54:08 tgl Exp $
1818
*/
1919

20+
/* This is intended to be used in both frontend and backend, so use c.h */
21+
#include "c.h"
2022

21-
#if ! defined(FRONTEND)
22-
#include "postgres.h"
2323
#include "libpq/crypt.h"
24-
#endif
25-
26-
#ifdef FRONTEND
27-
#include "postgres_fe.h"
28-
#include "libpq/crypt.h"
29-
30-
#undef palloc
31-
#define palloc malloc
32-
#undef pfree
33-
#define pfree free
34-
#endif /* FRONTEND */
3524

3625

3726
/*
@@ -325,9 +314,12 @@ pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len,
325314
char *buf)
326315
{
327316
size_t passwd_len = strlen(passwd);
328-
char *crypt_buf = palloc(passwd_len + salt_len);
317+
char *crypt_buf = malloc(passwd_len + salt_len);
329318
bool ret;
330319

320+
if (!crypt_buf)
321+
return false;
322+
331323
/*
332324
* Place salt at the end because it may be known by users trying to crack
333325
* the MD5 output.
@@ -338,7 +330,7 @@ pg_md5_encrypt(const char *passwd, const char *salt, size_t salt_len,
338330
strcpy(buf, "md5");
339331
ret = pg_md5_hash(crypt_buf, passwd_len + salt_len, buf + 3);
340332

341-
pfree(crypt_buf);
333+
free(crypt_buf);
342334

343335
return ret;
344336
}

0 commit comments

Comments
 (0)