mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Add missing error handling in pg_md5_hash().
It failed to provide an error string as expected for the admittedly-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 to reverse-engineer the API spec for a publicly visible routine.
This commit is contained in:
parent
36d4efe779
commit
587de223f0
@ -57,6 +57,9 @@ bytesToHex(uint8 b[16], char *s)
|
|||||||
* characters. you thus need to provide an array
|
* characters. you thus need to provide an array
|
||||||
* of 33 characters, including the trailing '\0'.
|
* of 33 characters, including the trailing '\0'.
|
||||||
*
|
*
|
||||||
|
* errstr filled with a constant-string error message
|
||||||
|
* on failure return; NULL on success.
|
||||||
|
*
|
||||||
* RETURNS false on failure (out of memory for internal buffers
|
* RETURNS false on failure (out of memory for internal buffers
|
||||||
* or MD5 computation failure) or true on success.
|
* or MD5 computation failure) or true on success.
|
||||||
*
|
*
|
||||||
@ -72,9 +75,13 @@ pg_md5_hash(const void *buff, size_t len, char *hexsum, const char **errstr)
|
|||||||
uint8 sum[MD5_DIGEST_LENGTH];
|
uint8 sum[MD5_DIGEST_LENGTH];
|
||||||
pg_cryptohash_ctx *ctx;
|
pg_cryptohash_ctx *ctx;
|
||||||
|
|
||||||
|
*errstr = NULL;
|
||||||
ctx = pg_cryptohash_create(PG_MD5);
|
ctx = pg_cryptohash_create(PG_MD5);
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
|
{
|
||||||
|
*errstr = pg_cryptohash_error(NULL); /* returns OOM */
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (pg_cryptohash_init(ctx) < 0 ||
|
if (pg_cryptohash_init(ctx) < 0 ||
|
||||||
pg_cryptohash_update(ctx, buff, len) < 0 ||
|
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)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pg_md5_binary
|
||||||
|
*
|
||||||
|
* As above, except that the MD5 digest is returned as a binary string
|
||||||
|
* (of size MD5_DIGEST_LENGTH) rather than being converted to ASCII hex.
|
||||||
|
*/
|
||||||
bool
|
bool
|
||||||
pg_md5_binary(const void *buff, size_t len, void *outbuf, const char **errstr)
|
pg_md5_binary(const void *buff, size_t len, void *outbuf, const char **errstr)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user