From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: hanwen@google.com, "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [PATCH] reftable: avoid undefined behaviour breaking t0032
Date: Fri, 15 Apr 2022 00:02:36 -0700 [thread overview]
Message-ID: <20220415070236.25280-1-carenas@gmail.com> (raw)
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
next reply other threads:[~2022-04-15 7:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-15 7:02 Carlo Marcelo Arenas Belón [this message]
2022-04-15 7:10 ` [PATCH] reftable: avoid undefined behaviour breaking t0032 Junio C Hamano
2022-04-15 8:30 ` [PATCH v2] " Carlo Marcelo Arenas Belón
2022-04-15 10:21 ` [RFC PATCH 0/2] reftable: remove poor man's SANITIZE=address, fix a memset() bug Ævar Arnfjörð Bjarmason
2022-04-15 10:21 ` [RFC PATCH 1/2] reftable: remove the "return_block" abstraction Ævar Arnfjörð Bjarmason
2022-04-15 13:37 ` René Scharfe
2022-04-25 9:57 ` Han-Wen Nienhuys
2022-04-25 17:30 ` Junio C Hamano
2022-04-15 10:21 ` [RFC PATCH 2/2] reftable: don't memset() a NULL from failed malloc() Ævar Arnfjörð Bjarmason
2022-04-15 13:37 ` René Scharfe
2022-04-15 13:53 ` Ævar Arnfjörð Bjarmason
2022-04-15 14:30 ` Phillip Wood
2022-04-15 15:20 ` Ævar Arnfjörð Bjarmason
2022-04-15 16:23 ` Junio C Hamano
2022-04-25 10:30 ` Han-Wen Nienhuys
2022-04-25 10:18 ` [PATCH v2] reftable: avoid undefined behaviour breaking t0032 Han-Wen Nienhuys
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220415070236.25280-1-carenas@gmail.com \
--to=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).