From: Dominic Chen <d.c.ddcc@gmail.com>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] mallocng/aligned_alloc: check for malloc failure
Date: Thu, 25 Mar 2021 18:26:04 -0400 [thread overview]
Message-ID: <07fe83ac-9893-bff0-3c15-4d431815684d@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 221 bytes --]
With mallocng, calling posix_memalign() or aligned_alloc() will SIGSEGV
if the internal malloc() call returns NULL. This does not occur with
oldmalloc, which explicitly checks for allocation failure.
Thanks,
Dominic
[-- Attachment #2: 0001-mallocng-aligned_alloc-check-for-malloc-failure.patch --]
[-- Type: text/plain, Size: 785 bytes --]
From 83a79b341f75ad243fba8603d889bfdebae3f35b Mon Sep 17 00:00:00 2001
From: Dominic Chen <d.c.ddcc@gmail.com>
Date: Thu, 25 Mar 2021 18:20:14 -0400
Subject: [PATCH] mallocng/aligned_alloc: check for malloc failure
---
src/malloc/mallocng/aligned_alloc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/malloc/mallocng/aligned_alloc.c b/src/malloc/mallocng/aligned_alloc.c
index 34116896..e0862a83 100644
--- a/src/malloc/mallocng/aligned_alloc.c
+++ b/src/malloc/mallocng/aligned_alloc.c
@@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len)
if (align <= UNIT) align = UNIT;
unsigned char *p = malloc(len + align - UNIT);
+ if (!p)
+ return 0;
+
struct meta *g = get_meta(p);
int idx = get_slot_index(p);
size_t stride = get_stride(g);
--
2.25.1
next reply other threads:[~2021-03-25 22:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 22:26 Dominic Chen [this message]
2021-04-16 14:17 ` Rich Felker
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=07fe83ac-9893-bff0-3c15-4d431815684d@gmail.com \
--to=d.c.ddcc@gmail.com \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).