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

Commit587de22

Browse files
committed
Add missing error handling in pg_md5_hash().
It failed to provide an error string as expected for theadmittedly-unlikely case of OOM in pg_cryptohash_create().Also, make it initialize *errstr to NULL for success,as pg_md5_binary() does.Also add missing comments. Readers should not have toreverse-engineer the API spec for a publicly visible routine.
1 parent36d4efe commit587de22

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎src/common/md5_common.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ bytesToHex(uint8 b[16], char *s)
5757
* characters. you thus need to provide an array
5858
* of 33 characters, including the trailing '\0'.
5959
*
60+
* errstr filled with a constant-string error message
61+
* on failure return; NULL on success.
62+
*
6063
*RETURNS false on failure (out of memory for internal buffers
6164
* or MD5 computation failure) or true on success.
6265
*
@@ -72,9 +75,13 @@ pg_md5_hash(const void *buff, size_t len, char *hexsum, const char **errstr)
7275
uint8sum[MD5_DIGEST_LENGTH];
7376
pg_cryptohash_ctx*ctx;
7477

78+
*errstr=NULL;
7579
ctx=pg_cryptohash_create(PG_MD5);
7680
if (ctx==NULL)
81+
{
82+
*errstr=pg_cryptohash_error(NULL);/* returns OOM */
7783
return false;
84+
}
7885

7986
if (pg_cryptohash_init(ctx)<0||
8087
pg_cryptohash_update(ctx,buff,len)<0||
@@ -90,6 +97,12 @@ pg_md5_hash(const void *buff, size_t len, char *hexsum, const char **errstr)
9097
return true;
9198
}
9299

100+
/*
101+
* pg_md5_binary
102+
*
103+
* As above, except that the MD5 digest is returned as a binary string
104+
* (of size MD5_DIGEST_LENGTH) rather than being converted to ASCII hex.
105+
*/
93106
bool
94107
pg_md5_binary(constvoid*buff,size_tlen,void*outbuf,constchar**errstr)
95108
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp