On Thu, 13 Aug 2020 19:31:04 -0600, Todd C. Miller wrote:
> The fix is to look at mode, not oflags since "w+" will set O_RDWR,
> not O_WRONLY.
Actually, checking O_TRUNC is probably better and is consistent
with the rest of the code. Either diff produces the expected results
from your test program.
- todd
Index: lib/libc/stdio/fmemopen.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/fmemopen.c,v
retrieving revision 1.3
diff -u -p -u -r1.3 fmemopen.c
--- lib/libc/stdio/fmemopen.c 31 Aug 2015 02:53:57 -0000 1.3
+++ lib/libc/stdio/fmemopen.c 14 Aug 2020 01:41:36 -0000
@@ -144,7 +144,7 @@ fmemopen(void *buf, size_t size, const c
}
st->pos = 0;
- st->len = (oflags & O_WRONLY) ? 0 : size;
+ st->len = (oflags & O_TRUNC) ? 0 : size;
st->size = size;
st->update = oflags & O_RDWR;