Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150794155
D47265.id145389.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D47265.id145389.diff
View Options
Index: lib/libc/stdio/fmemopen.c
===================================================================
--- lib/libc/stdio/fmemopen.c
+++ lib/libc/stdio/fmemopen.c
@@ -137,8 +137,8 @@
}
f = funopen(ck,
- flags & O_WRONLY ? NULL : fmemopen_read,
- flags & O_RDONLY ? NULL : fmemopen_write,
+ (flags & O_ACCMODE) == O_WRONLY ? NULL : fmemopen_read,
+ (flags & O_ACCMODE) == O_RDONLY ? NULL : fmemopen_write,
fmemopen_seek, fmemopen_close);
if (f == NULL) {
Index: lib/libc/tests/stdio/fmemopen2_test.c
===================================================================
--- lib/libc/tests/stdio/fmemopen2_test.c
+++ lib/libc/tests/stdio/fmemopen2_test.c
@@ -271,6 +271,32 @@
ATF_REQUIRE(errno == EINVAL);
}
+/* PR281953 */
+ATF_TC_WITHOUT_HEAD(test_rdonly_wronly);
+ATF_TC_BODY(test_rdonly_wronly, tc)
+{
+ FILE *fp;
+ char buf[16];
+ char buf_orig[16] = "input data";
+ char buf_write[16] = "write";
+ size_t sz;
+
+ memcpy(buf, buf_orig, sizeof(buf));
+ fp = fmemopen(buf, sizeof(buf), "r");
+ ATF_REQUIRE(fp != NULL);
+ sz = fwrite(buf_write, 1, strlen(buf_write), fp);
+ ATF_REQUIRE(sz == 0);
+ ATF_REQUIRE(errno == EBADF);
+ ATF_REQUIRE(memcmp(buf, buf_orig, sizeof(buf)) == 0);
+ fclose(fp);
+
+ fp = fmemopen(buf_orig, sizeof(buf), "w");
+ sz = fread(buf, sizeof(buf), 1, fp);
+ ATF_REQUIRE(sz == 0);
+ ATF_REQUIRE(errno == EBADF);
+ fclose(fp);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -280,6 +306,7 @@
ATF_TP_ADD_TC(tp, test_binary);
ATF_TP_ADD_TC(tp, test_append_binary_pos);
ATF_TP_ADD_TC(tp, test_size_0);
+ ATF_TP_ADD_TC(tp, test_rdonly_wronly);
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 2:36 AM (13 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30863135
Default Alt Text
D47265.id145389.diff (1 KB)
Attached To
Mode
D47265: libc: fix WRONLY/RDONLY test in fmemopen
Attached
Detach File
Event Timeline
Log In to Comment