From 3af56aa67c2ee450d5fe9bb9dd8b27ab96164ec4 Mon Sep 17 00:00:00 2001 From: yasuoka <> Date: Thu, 12 Jun 2025 07:39:26 +0000 Subject: Add a test to verify the fpurge problem doesn't happen. fpurge() mistaknely made the write buffer usable even if the stream is read mode. See the change of lib/libc/stdio/fpurge.c,v 1.11. --- src/regress/lib/libc/stdio/test___freading.c | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/regress/lib/libc/stdio/test___freading.c b/src/regress/lib/libc/stdio/test___freading.c index 05716f3a38..f74eb78d35 100644 --- a/src/regress/lib/libc/stdio/test___freading.c +++ b/src/regress/lib/libc/stdio/test___freading.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test___freading.c,v 1.1 2025/05/25 00:20:54 yasuoka Exp $ */ +/* $OpenBSD: test___freading.c,v 1.2 2025/06/12 07:39:26 yasuoka Exp $ */ /* * Copyright (c) 2025 YASUOKA Masahiko @@ -21,14 +21,31 @@ #include #include #include +#include /* we use assert() */ #undef NDEBUG #define TMPFILENAME "test___freading.tmp" +void setup(void); + void test___freading0(void); void test___freading1(void); +void test___freading2(void); + +void +setup(void) +{ + FILE *fp; + + /* common setup */ + unlink(TMPFILENAME); + fp = fopen(TMPFILENAME, "w+"); + assert(fp != NULL); + fputs("Hello world\n", fp); + fclose(fp); +} void test___freading0(void) @@ -75,11 +92,34 @@ test___freading1(void) assert(r == 0); } +void +test___freading2(void) +{ + int r; + FILE *fp; + + /* + * until v1.10 of fpurge.c mistakenly enables the writing buffer + * without _SRD flag set. + */ + fp = fopen(TMPFILENAME, "r+"); + assert(fp != NULL); + assert(fgetc(fp) == 'H'); + fpurge(fp); + fseek(fp, 0, SEEK_CUR); + assert(fputc('X', fp) == 'X'); + assert(__freading(fp) == 0); + + r = fclose(fp); + assert(r == 0); +} + int main(int argc, char *argv[]) { test___freading0(); test___freading1(); + test___freading2(); exit(0); } -- cgit v1.2.3-55-g6feb