[PATCH] reftable: avoid undefined behaviour breaking t0032
- From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
- Date
- Apr 15, 2022, 07:02 UTC
- Message-ID
- <20220415070236.25280-1-carenas@gmail.com>
At least in glibc based systems, memset with a NULL first parameter will cause a runtime exception.
Avoid doing so by adding a conditional to check for NULL in all three identically looking functions that were affected.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> --- Bug was introduced with the original code in 1214aa841bc (reftable: add blocksource, an abstraction for random access reads, 2021-10-07), so not to be considered a regression for this release.
reftable/blocksource.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/reftable/blocksource.c b/reftable/blocksource.c index 0044eecd9aa..984bf07fc17 100644 --- a/reftable/blocksource.c +++ b/reftable/blocksource.c @@ -15,7 +15,8 @@ license that can be found in the LICENSE file or at static void strbuf_return_block(void *b, struct reftable_block *dest) { - memset(dest->data, 0xff, dest->len); + if (dest->data) + memset(dest->data, 0xff, dest->len); reftable_free(dest->data); } @@ -56,7 +57,8 @@ void block_source_from_strbuf(struct reftable_block_source *bs, static void malloc_return_block(void *b, struct reftable_block *dest) { - memset(dest->data, 0xff, dest->len); + if (dest->data) + memset(dest->data, 0xff, dest->len); reftable_free(dest->data); } @@ -85,7 +87,8 @@ static uint64_t file_size(void *b) static void file_return_block(void *b, struct reftable_block *dest) { - memset(dest->data, 0xff, dest->len); + if (dest->data) + memset(dest->data, 0xff, dest->len); reftable_free(dest->data); }
-- 2.36.0.rc2.283.gbef64175c85