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

Commit44f1833

Browse files
committed
Put MD5 salt at the end for security.
1 parent90aebf7 commit44f1833

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

‎src/backend/libpq/md5.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Sverre H. Huseby <sverrehu@online.no>
1212
*
13-
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.6 2001/09/21 20:31:47 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.7 2001/09/27 23:16:23 momjian Exp $
1414
*/
1515

1616
#include"postgres.h"
@@ -19,6 +19,14 @@
1919

2020
#include"libpq/crypt.h"
2121

22+
#ifdefFRONTEND
23+
#undef palloc
24+
#definepalloc malloc
25+
#undef pfree
26+
#definepfree free
27+
#endif
28+
29+
2230
/*
2331
*PRIVATE FUNCTIONS
2432
*/
@@ -289,15 +297,19 @@ md5_hash(const void *buff, size_t len, char *hexsum)
289297
boolEncryptMD5(constchar*passwd,constchar*salt,size_tsalt_len,
290298
char*buf)
291299
{
292-
charcrypt_buf[128];
293-
294-
if (salt_len+strlen(passwd)>127)
295-
return false;
296-
300+
char*crypt_buf=palloc(strlen(passwd)+salt_len);
301+
boolret;
302+
297303
strcpy(buf,"md5");
298-
memset(crypt_buf,0,128);
299-
memcpy(crypt_buf,salt,salt_len);
300-
memcpy(crypt_buf+salt_len,passwd,strlen(passwd));
304+
/*
305+
*Place salt at the end because it may be known by users
306+
*trying to crack the MD5 output.
307+
*/
308+
strcpy(crypt_buf,passwd);
309+
memcpy(crypt_buf+strlen(passwd),salt,salt_len);
310+
311+
ret=md5_hash(crypt_buf,strlen(passwd)+salt_len,buf+3);
312+
pfree(crypt_buf);
301313

302-
returnmd5_hash(crypt_buf,salt_len+strlen(passwd),buf+3);
314+
returnret;
303315
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp