diff options
author | Michael Paquier <michael@paquier.xyz> | 2022-01-14 11:25:39 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2022-01-14 11:25:39 +0900 |
commit | ad5b6f248ab288c3252d8122d12a1eb410d4a0b6 (patch) | |
tree | dd914d58c9e73ef85bad9978e7c249462374a404 /src/backend/utils/adt/cryptohashfuncs.c | |
parent | 4aee39ddb8fa748a6beea2bc1b48882990c226a7 (diff) | |
download | postgresql-ad5b6f248ab288c3252d8122d12a1eb410d4a0b6.tar.gz postgresql-ad5b6f248ab288c3252d8122d12a1eb410d4a0b6.zip |
Revert error handling improvements for cryptohashes
This reverts commits ab27df2, af8d530 and 3a0cced, that introduced
pg_cryptohash_error(). In order to make the core code able to pass down
the new error types that this introduced, some of the MD5-related
routines had to be reworked, causing an ABI breakage, but we found that
some external extensions rely on them. Maintaining compatibility
outweights the error report benefits, so just revert the change in v14.
Reported-by: Laurenz Albe
Discussion: https://postgr.es/m/9f0c0a96d28cf14fc87296bbe67061c14eb53ae8.camel@cybertec.at
Diffstat (limited to 'src/backend/utils/adt/cryptohashfuncs.c')
-rw-r--r-- | src/backend/utils/adt/cryptohashfuncs.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/backend/utils/adt/cryptohashfuncs.c b/src/backend/utils/adt/cryptohashfuncs.c index c977db2f0ea..6a0f0258e60 100644 --- a/src/backend/utils/adt/cryptohashfuncs.c +++ b/src/backend/utils/adt/cryptohashfuncs.c @@ -35,17 +35,15 @@ md5_text(PG_FUNCTION_ARGS) text *in_text = PG_GETARG_TEXT_PP(0); size_t len; char hexsum[MD5_HASH_LEN + 1]; - const char *errstr = NULL; /* Calculate the length of the buffer using varlena metadata */ len = VARSIZE_ANY_EXHDR(in_text); /* get the hash result */ - if (pg_md5_hash(VARDATA_ANY(in_text), len, hexsum, &errstr) == false) + if (pg_md5_hash(VARDATA_ANY(in_text), len, hexsum) == false) ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("could not compute %s hash: %s", "MD5", - errstr))); + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); /* convert to text and return it */ PG_RETURN_TEXT_P(cstring_to_text(hexsum)); @@ -60,14 +58,12 @@ md5_bytea(PG_FUNCTION_ARGS) bytea *in = PG_GETARG_BYTEA_PP(0); size_t len; char hexsum[MD5_HASH_LEN + 1]; - const char *errstr = NULL; len = VARSIZE_ANY_EXHDR(in); - if (pg_md5_hash(VARDATA_ANY(in), len, hexsum, &errstr) == false) + if (pg_md5_hash(VARDATA_ANY(in), len, hexsum) == false) ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("could not compute %s hash: %s", "MD5", - errstr))); + (errcode(ERRCODE_OUT_OF_MEMORY), + errmsg("out of memory"))); PG_RETURN_TEXT_P(cstring_to_text(hexsum)); } @@ -115,15 +111,12 @@ cryptohash_internal(pg_cryptohash_type type, bytea *input) ctx = pg_cryptohash_create(type); if (pg_cryptohash_init(ctx) < 0) - elog(ERROR, "could not initialize %s context: %s", typestr, - pg_cryptohash_error(ctx)); + elog(ERROR, "could not initialize %s context", typestr); if (pg_cryptohash_update(ctx, data, len) < 0) - elog(ERROR, "could not update %s context: %s", typestr, - pg_cryptohash_error(ctx)); + elog(ERROR, "could not update %s context", typestr); if (pg_cryptohash_final(ctx, (unsigned char *) VARDATA(result), digest_len) < 0) - elog(ERROR, "could not finalize %s context: %s", typestr, - pg_cryptohash_error(ctx)); + elog(ERROR, "could not finalize %s context", typestr); pg_cryptohash_free(ctx); SET_VARSIZE(result, digest_len + VARHDRSZ); |