[v3] libio: Fix fmemopen_write on appending condition
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
* libio/fmemopen.c: reference pos the variable instead of c->pos
To reproduce, write a C unit with the following code and then compile it
and run it, should expect an output with "1 No space left on device".
Apparently, for appending mode, there is enough room to write some
bytes, but it didn't. `c->pos` should be corrected to `pos`.
Signed-off-by: Rocket Ma <marocketbd@gmail.com>
---
libio/Makefile | 1 +
libio/bug-fmemopen.c | 37 +++++++++++++++++++++++++++++++++++++
libio/fmemopen.c | 2 +-
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 libio/bug-fmemopen.c
@@ -70,6 +70,7 @@ routines_no_fortify += \
# routines_no_fortify
tests = \
+ bug-fmemopen \
bug-fopena+ \
bug-fseek \
bug-ftell \
new file mode 100644
@@ -0,0 +1,37 @@
+/* Regression test for fmemopen bug BZ 34006
+ Copyright (C) 2021-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <support/check.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+ char buf[5] = "1";
+ FILE *fp = fmemopen (buf, 4, "a+");
+ TEST_VERIFY (fp);
+ TEST_VERIFY (fseek (fp, 3, SEEK_SET) == 0);
+ setbuf (fp, NULL);
+ TEST_VERIFY (fwrite ("XXXX", 1, 4, fp) > 0);
+ TEST_COMPARE_STRING (buf, "1XXX");
+ fclose (fp);
+
+ return 0;
+}
+
+#include <support/test-driver.c>
@@ -71,7 +71,7 @@ fmemopen_write (void *cookie, const char *b, size_t s)
if (pos + s > c->size)
{
- if ((size_t) (c->pos + addnullc) >= c->size)
+ if ((size_t) (pos + addnullc) >= c->size)
{
__set_errno (ENOSPC);
return 0;