Page MenuHomeFreeBSD

libc: fix WRONLY/RDONLY test in fmemopen
ClosedPublic

Authored by emaste on Oct 23 2024, 1:43 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 29, 12:15 AM
Unknown Object (File)
Thu, Nov 27, 11:11 AM
Unknown Object (File)
Nov 13 2025, 4:50 AM
Unknown Object (File)
Nov 11 2025, 12:38 AM
Unknown Object (File)
Nov 4 2025, 10:32 PM
Unknown Object (File)
Oct 29 2025, 9:26 PM
Unknown Object (File)
Oct 29 2025, 9:07 PM
Unknown Object (File)
Oct 29 2025, 9:07 PM
Subscribers

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

emaste created this revision.
This revision is now accepted and ready to land.Oct 23 2024, 3:28 PM
fuz requested changes to this revision.Oct 23 2024, 3:35 PM
fuz added a subscriber: fuz.

Code should account for O_RDWR case.
The earlier test if (!(flags & O_RDWR) && buf == NULL) in the same file fmemopen.c is also dubious and should be adjusted similarly.
Test should also check a read/write mode like "r+" or "w+".

lib/libc/stdio/fmemopen.c
141

What happens if fmemopen() is called with mode "r+" or "w+", yielding (flags & O_ACCMODE) == O_RDWR?

This revision now requires changes to proceed.Oct 23 2024, 3:35 PM
lib/libc/stdio/fmemopen.c
141

oops, that's a nice catch.

lib/libc/stdio/fmemopen.c
141

Then both tests are false and we use fmemopen_read and fmemopen_write?

lib/libc/stdio/fmemopen.c
141

yep, that sounds correct.

r+ and w+ are implicitly tested in other test cases; I'm not sure we need to duplicate that (but could add a comment).

add a comment, fix another case reported by @fuz (that worked by accident, as it turns out)

This revision is now accepted and ready to land.Oct 23 2024, 4:28 PM
This revision was automatically updated to reflect the committed changes.
jrtc27 added inline comments.
lib/libc/tests/stdio/fmemopen2_test.c
296

as above