Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261119141613.GC5716@brightrain.aerifal.cx>
Date: Thu, 19 Nov 2026 09:16:13 -0500
From: Rich Felker <dalias@...c.org>
To: zhaotq@....edu.cn
Cc: musl@...ts.openwall.com
Subject: Re: musl libc 1.2.5: fmemopen(NULL, 0, "w+") writes past a
 zero-capacity buffer

On Thu, Nov 19, 2026 at 01:34:05PM +0800, zhaotq@....edu.cn wrote:
> Hello,
> 
> We found a deterministic one-byte heap out-of-bounds write in musl 1.2.5:
> 
>     fmemopen(NULL, 0, "w+");
> 
> When buf is null and max_size is zero, musl allocates a memory stream object
> with no bytes available in its dynamic data area. It then executes the
> following write for every mode containing '+':
> 
>     else if (plus) *f->c.buf = 0;

I belive the following fixes it:

diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c
index 38ba9f85..bf2ce57f 100644
--- a/src/stdio/fmemopen.c
+++ b/src/stdio/fmemopen.c
@@ -118,7 +118,7 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode)
 	if (!plus) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD;
 	if (*mode == 'r') f->c.len = size;
 	else if (*mode == 'a') f->c.len = f->c.pos = strnlen(buf, size);
-	else if (plus) *f->c.buf = 0;
+	else if (plus && size) *f->c.buf = 0;
 
 	f->f.read = mread;
 	f->f.write = mwrite;

> We would appreciate your assessment of the security impact and whether
> a CVE is warranted. 

No.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.