Skip to content

Commit 742d0f2

Browse files
committed
Clean up comments.
1 parent 2a314ad commit 742d0f2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/backend/libpq/md5.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
*
1111
* Sverre H. Huseby <sverrehu@online.no>
1212
*
13-
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.7 2001/09/27 23:16:23 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.8 2001/09/29 19:49:50 tgl Exp $
1414
*/
1515

1616
#include "postgres.h"
1717

18-
#include <errno.h>
19-
2018
#include "libpq/crypt.h"
2119

2220
#ifdef FRONTEND
@@ -291,24 +289,31 @@ md5_hash(const void *buff, size_t len, char *hexsum)
291289

292290

293291
/*
294-
* puts md5(username+passwd) in buf provided buflen is at least 36 bytes
295-
* returns 1 on success, 0 on any kind of failure and sets errno accordingly
292+
* Computes MD5 checksum of "passwd" (a null-terminated string) followed
293+
* by "salt" (which need not be null-terminated).
294+
*
295+
* Output format is "md5" followed by a 32-hex-digit MD5 checksum.
296+
* Hence, the output buffer "buf" must be at least 36 bytes long.
297+
*
298+
* Returns TRUE if okay, FALSE on error (out of memory).
296299
*/
297300
bool EncryptMD5(const char *passwd, const char *salt, size_t salt_len,
298301
char *buf)
299302
{
300-
char *crypt_buf = palloc(strlen(passwd) + salt_len);
303+
size_t passwd_len = strlen(passwd);
304+
char *crypt_buf = palloc(passwd_len + salt_len);
301305
bool ret;
302306

303-
strcpy(buf, "md5");
304307
/*
305308
* Place salt at the end because it may be known by users
306309
* trying to crack the MD5 output.
307310
*/
308311
strcpy(crypt_buf, passwd);
309-
memcpy(crypt_buf+strlen(passwd), salt, salt_len);
312+
memcpy(crypt_buf+passwd_len, salt, salt_len);
313+
314+
strcpy(buf, "md5");
315+
ret = md5_hash(crypt_buf, passwd_len + salt_len, buf + 3);
310316

311-
ret = md5_hash(crypt_buf, strlen(passwd) + salt_len, buf + 3);
312317
pfree(crypt_buf);
313318

314319
return ret;

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