Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Han-Wen Nienhuys <hanwen@google.com>, Patrick Steinhardt <ps@pks.im>
Subject: [PATCH] reftable: use xmalloc() and xrealloc()
Date: Sat, 6 Apr 2024 22:37:55 +0200	[thread overview]
Message-ID: <963961ee-0f1d-42b8-8dda-5838e7a2ed94@web.de> (raw)

malloc(3) and realloc(3) can fail and return NULL.  None of the reftable
code checks for that possibility and would happily dereference NULL
pointers.  Use xmalloc() and xrealloc() instead like in the rest of Git
to report allocation errors and exit cleanly, and to also honor the
environment variable GIT_ALLOC_LIMIT.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 reftable/publicbasics.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/reftable/publicbasics.c b/reftable/publicbasics.c
index 44b84a125e..f33a65df34 100644
--- a/reftable/publicbasics.c
+++ b/reftable/publicbasics.c
@@ -19,14 +19,14 @@ void *reftable_malloc(size_t sz)
 {
 	if (reftable_malloc_ptr)
 		return (*reftable_malloc_ptr)(sz);
-	return malloc(sz);
+	return xmalloc(sz);
 }

 void *reftable_realloc(void *p, size_t sz)
 {
 	if (reftable_realloc_ptr)
 		return (*reftable_realloc_ptr)(p, sz);
-	return realloc(p, sz);
+	return xrealloc(p, sz);
 }

 void reftable_free(void *p)
--
2.44.0

             reply	other threads:[~2024-04-06 20:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-06 20:37 René Scharfe [this message]
2024-04-08  5:44 ` [PATCH] reftable: use xmalloc() and xrealloc() Patrick Steinhardt
2024-04-08 15:42   ` Junio C Hamano
2024-04-08 16:33     ` Patrick Steinhardt
2024-04-08 17:50   ` Han-Wen Nienhuys
2024-04-08 20:36     ` Junio C Hamano
2024-04-09  3:24     ` Patrick Steinhardt

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=963961ee-0f1d-42b8-8dda-5838e7a2ed94@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=hanwen@google.com \
    --cc=ps@pks.im \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).