postgresql/src/common
Michael Paquier b83dcf7928 Add result size as argument of pg_cryptohash_final() for overflow checks
With its current design, a careless use of pg_cryptohash_final() could
would result in an out-of-bound write in memory as the size of the
destination buffer to store the result digest is not known to the
cryptohash internals, without the caller knowing about that.  This
commit adds a new argument to pg_cryptohash_final() to allow such sanity
checks, and implements such defenses.

The internals of SCRAM for HMAC could be tightened a bit more, but as
everything is based on SCRAM_KEY_LEN with uses particular to this code
there is no need to complicate its interface more than necessary, and
this comes back to the refactoring of HMAC in core.  Except that, this
minimizes the uses of the existing DIGEST_LENGTH variables, relying
instead on sizeof() for the result sizes.  In ossp-uuid, this also makes
the code more defensive, as it already relied on dce_uuid_t being at
least the size of a MD5 digest.

This is in philosophy similar to cfc40d3 for base64.c and aef8948 for
hex.c.

Reported-by: Ranier Vilela
Author: Michael Paquier, Ranier Vilela
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/CAEudQAoqEGmcff3J4sTSV-R_16Monuz-UpJFbf_dnVH=APr02Q@mail.gmail.com
2021-02-15 10:18:34 +09:00
..
unicode Update copyright for 2021 2021-01-02 13:06:25 -05:00
.gitignore Replace the data structure used for keyword lookup. 2019-01-06 17:02:57 -05:00
Makefile Introduce --with-ssl={openssl} as a configure option 2021-02-01 19:19:44 +09:00
archive.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
base64.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
checksum_helper.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
config_info.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
controldata_utils.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
cryptohash.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
cryptohash_openssl.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
d2s.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
d2s_full_table.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
d2s_intrinsics.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
digit_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
encnames.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
exec.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
f2s.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
fe_memutils.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
file_perm.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
file_utils.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
hashfn.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
hex.c Rework refactoring of hex and encoding routines 2021-01-14 11:13:24 +09:00
ip.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
jsonapi.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
keywords.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
kwlookup.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
link-canary.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
logging.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
md5.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
md5_common.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
md5_int.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_get_line.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_lzcompress.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgfnames.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
protocol_openssl.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
psprintf.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
relpath.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
restricted_token.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
rmtree.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
ryu_common.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
saslprep.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
scram-common.c Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
sha1.c Introduce SHA1 implementations in the cryptohash infrastructure 2021-01-23 11:33:04 +09:00
sha1_int.h Introduce SHA1 implementations in the cryptohash infrastructure 2021-01-23 11:33:04 +09:00
sha2.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
sha2_int.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
sprompt.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
string.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
stringinfo.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
unicode_norm.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
username.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
wait_error.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
wchar.c Add mbverifystr() functions specific to each encoding. 2021-01-28 14:40:07 +02:00