{"id":2234838,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2234838/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/patch/20260508060410.13725-3-gaoxiang@kylinos.cn/","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.2/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260508060410.13725-3-gaoxiang@kylinos.cn>","list_archive_url":null,"date":"2026-05-08T06:04:10","name":"[v5,2/2] libio: Ignore doallocate for open_memstream and open_wmemstream [BZ #34019]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"8ad59ac81f0d7fe96bc23ada1bc81ae77471d23d","submitter":{"id":92909,"url":"http://patchwork.ozlabs.org/api/1.2/people/92909/?format=json","name":"Gao Xiang","email":"gaoxiang@kylinos.cn"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/20260508060410.13725-3-gaoxiang@kylinos.cn/mbox/","series":[{"id":503327,"url":"http://patchwork.ozlabs.org/api/1.2/series/503327/?format=json","web_url":"http://patchwork.ozlabs.org/project/glibc/list/?series=503327","date":"2026-05-08T06:04:09","name":"libio: Keep memstream result buffers independent of setvbuf","version":5,"mbox":"http://patchwork.ozlabs.org/series/503327/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2234838/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2234838/checks/","tags":{},"related":[],"headers":{"Return-Path":"<libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":["incoming@patchwork.ozlabs.org","libc-alpha@sourceware.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","libc-alpha@sourceware.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n dmarc=none (p=none dis=none) header.from=kylinos.cn","sourceware.org; spf=pass smtp.mailfrom=kylinos.cn","sourceware.org;\n arc=none smtp.remote-ip=124.126.103.232"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4gBdv50zqFz1yJq\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 08 May 2026 16:07:29 +1000 (AEST)","from vm01.sourceware.org (localhost [IPv6:::1])\n\tby sourceware.org (Postfix) with ESMTP id BCEA14BA2E1F\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  8 May 2026 06:07:26 +0000 (GMT)","from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232])\n by sourceware.org (Postfix) with ESMTPS id D45884BA2E14\n for <libc-alpha@sourceware.org>; Fri,  8 May 2026 06:07:02 +0000 (GMT)","from bogon [(117.61.28.11)] by mailgw.kylinos.cn\n (envelope-from <gaoxiang@kylinos.cn>)\n (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256)\n with ESMTP id 1515935329; Fri, 08 May 2026 14:06:53 +0800"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org BCEA14BA2E1F","OpenDKIM Filter v2.11.0 sourceware.org D45884BA2E14"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org D45884BA2E14","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org D45884BA2E14","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778220423; cv=none;\n b=vM6EAShfl+3adf2oP/R7aP4hr29ZZd1UWpszMluJ+oRERBrFfupSG8GUtU8zW1fNgJCHdDaUi7PRq2rmUZc62HlS0HDmx3IOpid+yGXoR2UjuhyvksKBgboc5Xmas5wqYPpcmBXHqe3E+g/eJR/SzNtER+qDYkRFC4JGqTiMEOg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1778220423; c=relaxed/simple;\n bh=uUIV1LcJlsxV1ELSYHv5ADQts42XLC1rNU3CTn9mb/M=;\n h=From:To:Subject:Date:Message-ID:MIME-Version;\n b=CVC9UCfQ/650hbnj7ClnOXFhPcqudtpIRI+yvIFD9on7uzkpXnNYY5ABQo90XtpPkHG3RGocaTmXWrv4vNBMIKe8yRo1efNbFYRQIvYrQ1uKRwShUwhAyNqZHJpK7xn3S6LyKShH29Zykx+hiDd6fdckGlauxG++QhmlJTi3+iM=","ARC-Authentication-Results":"i=1; sourceware.org","X-UUID":["1c7deb0c4aa411f1aa26b74ffac11d73-20260508","1c7deb0c4aa411f1aa26b74ffac11d73-20260508"],"X-CTIC-Tags":"HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CTE_8B,\n HR_CTT_MISS\n HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME, HR_SJ_DIGIT_LEN\n HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE\n HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME\n IP_UNTRUSTED, SRC_UNTRUSTED, IP_UNFAMILIAR, SRC_UNFAMILIAR, DN_TRUSTED\n SRC_TRUSTED, SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS\n DKIM_NOPASS, DMARC_NOPASS, UD_TRUSTED, CIE_GOOD_SPF, CIE_UNKNOWN\n GTI_FG_BS, GTI_C_CI, GTI_FG_IT, GTI_RG_INFO, GTI_C_BU\n AMN_T1, AMN_GOOD, AMN_C_TI, ABX_MISS_RDNS","X-CID-O-RULE":"Release_Ham","X-CID-RULE":"Release_Ham","X-CID-O-INFO":"VERSION:1.3.12, REQID:c04afb81-413c-44ec-b843-726f8ad2bd48,\n IP:10,\n URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTIO\n N:release,TS:5","X-CID-INFO":"VERSION:1.3.12, REQID:c04afb81-413c-44ec-b843-726f8ad2bd48, IP:10,\n UR\n L:0,TC:0,Content:0,EDM:0,RT:0,SF:-5,FILE:0,BULK:0,RULE:Release_Ham,ACTION:\n release,TS:5","X-CID-META":"VersionHash:e7bac3a, CLOUDID:87bdda229b78015adf4fed1314604f10,\n BulkI\n D:260508140655SU4Q1A6M,BulkQuantity:0,Recheck:0,SF:17|19|66|78|81|82|102|1\n 27|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:1,File:nil,RT:nil,Bulk:nil,\n QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0\n ,ARC:0","X-CID-BVR":"2,SSN|SDN","X-CID-BAS":"2,SSN|SDN,0,_","X-CID-FACTOR":"TF_CID_SPAM_FSD,TF_CID_SPAM_ULS,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS","X-CID-RHF":"D41D8CD98F00B204E9800998ECF8427E","X-User":"gaoxiang@kylinos.cn","From":"Gao Xiang <gaoxiang@kylinos.cn>","To":"libc-alpha@sourceware.org","Cc":"Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,\n Andreas Schwab <schwab@suse.de>, Rocket Ma <marocketbd@gmail.com>,\n Xiang Gao <gaoxiang@kylinos.cn>","Subject":"[PATCH v5 2/2] libio: Ignore doallocate for open_memstream and\n open_wmemstream [BZ #34019]","Date":"Fri,  8 May 2026 14:04:10 +0800","Message-ID":"<20260508060410.13725-3-gaoxiang@kylinos.cn>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260508060410.13725-1-gaoxiang@kylinos.cn>","References":"<20260507094000.22966-1-gaoxiang@kylinos.cn>\n <20260508060410.13725-1-gaoxiang@kylinos.cn>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libc-alpha@sourceware.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Libc-alpha mailing list <libc-alpha.sourceware.org>","List-Unsubscribe":"<https://sourceware.org/mailman/options/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe>","List-Archive":"<https://sourceware.org/pipermail/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-request@sourceware.org?subject=help>","List-Subscribe":"<https://sourceware.org/mailman/listinfo/libc-alpha>,\n <mailto:libc-alpha-request@sourceware.org?subject=subscribe>","Errors-To":"libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org"},"content":"From: Xiang Gao <gaoxiang@kylinos.cn>\n\nsetvbuf (stream, NULL, _IOFBF, 0) takes a special path in\n_IO_setvbuf: if the byte-oriented buffer base is NULL, it calls\n_IO_DOALLOCATE and returns without invoking the stream setbuf hook.\n\nFor open_wmemstream, the byte-oriented buffer base is NULL although\nthe wide result buffer has already been initialized in _wide_data.\nAs a result, this path calls _IO_wdefault_doallocate, which may\nreplace the wide buffer managed by open_wmemstream.\n\nInstall an open_wmemstream-specific doallocate hook that leaves\nthe growable result buffer unchanged. Add a regression test for this\npath.\n\nInstall a narrow memstream doallocate hook as well. It keeps both\nmemstream vtables consistent (generic stdio allocation must not\nreplace the growable result buffer).\n\nSigned-off-by: Xiang Gao <gaoxiang@kylinos.cn>\n---\n libio/Makefile                            |  2 +\n libio/libioP.h                            |  2 +\n libio/memstream.c                         |  9 ++++\n libio/tst-memstream-setvbuf-doallocate.c  | 61 +++++++++++++++++++++++\n libio/tst-wmemstream-setvbuf-doallocate.c | 20 ++++++++\n libio/vtables.c                           |  6 ++-\n libio/wmemstream.c                        |  9 ++++\n 7 files changed, 107 insertions(+), 2 deletions(-)\n create mode 100644 libio/tst-memstream-setvbuf-doallocate.c\n create mode 100644 libio/tst-wmemstream-setvbuf-doallocate.c","diff":"diff --git a/libio/Makefile b/libio/Makefile\nindex 6b56567d44..e165a8b4cb 100644\n--- a/libio/Makefile\n+++ b/libio/Makefile\n@@ -117,6 +117,7 @@ tests = \\\n   tst-fwrite-error \\\n   tst-getdelim \\\n   tst-memstream-setbuf \\\n+  tst-memstream-setvbuf-doallocate \\\n   tst-memstream1 \\\n   tst-memstream2 \\\n   tst-memstream3 \\\n@@ -141,6 +142,7 @@ tests = \\\n   tst-wfiledoallocate-static \\\n   tst-widetext \\\n   tst-wmemstream-setbuf \\\n+  tst-wmemstream-setvbuf-doallocate \\\n   tst-wmemstream1 \\\n   tst-wmemstream2 \\\n   tst-wmemstream3 \\\ndiff --git a/libio/libioP.h b/libio/libioP.h\nindex fa44ad0e57..f1a4a896a3 100644\n--- a/libio/libioP.h\n+++ b/libio/libioP.h\n@@ -742,10 +742,12 @@ extern int _IO_mem_sync (FILE* fp) __THROW attribute_hidden;\n extern void _IO_mem_finish (FILE* fp, int) __THROW attribute_hidden;\n extern FILE *_IO_mem_setbuf (FILE *fp, char *buf, ssize_t size)\n   __THROW attribute_hidden;\n+extern int _IO_mem_doallocate (FILE *fp) __THROW attribute_hidden;\n extern int _IO_wmem_sync (FILE* fp) __THROW attribute_hidden;\n extern void _IO_wmem_finish (FILE* fp, int) __THROW attribute_hidden;\n extern FILE *_IO_wmem_setbuf (FILE *fp, char *buf, ssize_t size)\n   __THROW attribute_hidden;\n+extern int _IO_wmem_doallocate (FILE *fp) __THROW attribute_hidden;\n \n /* Other strfile functions */\n struct _IO_strfile_;\ndiff --git a/libio/memstream.c b/libio/memstream.c\nindex 69b400d928..1af7224ab5 100644\n--- a/libio/memstream.c\n+++ b/libio/memstream.c\n@@ -120,3 +120,12 @@ _IO_mem_setbuf (FILE *fp, char *p, ssize_t len)\n   /* Memstream manage a growable buffer internally.  */\n   return fp;\n }\n+\n+\n+int\n+_IO_mem_doallocate (FILE *fp)\n+{\n+  /* Memstream manage a growable buffer internally.  The doallocate\n+     hook must not replace it with a generic stdio buffer.  */\n+  return 1;\n+}\ndiff --git a/libio/tst-memstream-setvbuf-doallocate.c b/libio/tst-memstream-setvbuf-doallocate.c\nnew file mode 100644\nindex 0000000000..aa6f86f02d\n--- /dev/null\n+++ b/libio/tst-memstream-setvbuf-doallocate.c\n@@ -0,0 +1,61 @@\n+/* Test setvbuf on open_memstream, BZ #34019.\n+   Copyright (C) 2026 Free Software Foundation, Inc.\n+   This file is part of the GNU C Library.\n+\n+   The GNU C Library is free software; you can redistribute it and/or\n+   modify it under the terms of the GNU Lesser General Public\n+   License as published by the Free Software Foundation; either\n+   version 2.1 of the License, or (at your option) any later version.\n+\n+   The GNU C Library is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+   Lesser General Public License for more details.\n+\n+   You should have received a copy of the GNU Lesser General Public\n+   License along with the GNU C Library; if not, see\n+   <https://www.gnu.org/licenses/>.  */\n+\n+#include <libio/tst-memstream.h>\n+\n+static int\n+do_test (void)\n+{\n+  /* Regression test for setvbuf doallocate on open_memstream and\n+     open_wmemstream.  This test covers the _IO_setvbuf path for:\n+\n+     setvbuf (stream, NULL, _IOFBF, 0)\n+\n+     This path may call _IO_DOALLOCATE and return without invoking\n+     the stream setbuf hook.  The generic doallocate hook must not\n+     replace the growable result buffer.  */\n+\n+  CHAR_T *buf = NULL;\n+  size_t len = 0;\n+  FILE *fp = OPEN_MEMSTREAM (&buf, &len);\n+\n+  TEST_VERIFY_EXIT (fp != NULL);\n+\n+  TEST_COMPARE (setvbuf (fp, NULL, _IOFBF, 0), 0);\n+\n+  TEST_COMPARE (FPUTC (W('A'), fp), W('A'));\n+  TEST_COMPARE (fflush (fp), 0);\n+  TEST_COMPARE (len, 1);\n+  TEST_VERIFY_EXIT (buf != NULL);\n+  TEST_VERIFY (buf[0] == W('A'));\n+  TEST_VERIFY (buf[1] == W('\\0'));\n+\n+  TEST_COMPARE (FPUTC (W('B'), fp), W('B'));\n+  TEST_COMPARE (fclose (fp), 0);\n+  TEST_COMPARE (len, 2);\n+  TEST_VERIFY_EXIT (buf != NULL);\n+  TEST_VERIFY (buf[0] == W('A'));\n+  TEST_VERIFY (buf[1] == W('B'));\n+  TEST_VERIFY (buf[2] == W('\\0'));\n+\n+  free (buf);\n+\n+  return 0;\n+}\n+\n+#include <support/test-driver.c>\ndiff --git a/libio/tst-wmemstream-setvbuf-doallocate.c b/libio/tst-wmemstream-setvbuf-doallocate.c\nnew file mode 100644\nindex 0000000000..857239aa85\n--- /dev/null\n+++ b/libio/tst-wmemstream-setvbuf-doallocate.c\n@@ -0,0 +1,20 @@\n+/* Test setvbuf on open_wmemstream, BZ #34019.\n+   Copyright (C) 2026 Free Software Foundation, Inc.\n+   This file is part of the GNU C Library.\n+\n+   The GNU C Library is free software; you can redistribute it and/or\n+   modify it under the terms of the GNU Lesser General Public\n+   License as published by the Free Software Foundation; either\n+   version 2.1 of the License, or (at your option) any later version.\n+\n+   The GNU C Library is distributed in the hope that it will be useful,\n+   but WITHOUT ANY WARRANTY; without even the implied warranty of\n+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+   Lesser General Public License for more details.\n+\n+   You should have received a copy of the GNU Lesser General Public\n+   License along with the GNU C Library; if not, see\n+   <https://www.gnu.org/licenses/>.  */\n+\n+#define TEST_WCHAR\n+#include <libio/tst-memstream-setvbuf-doallocate.c>\ndiff --git a/libio/vtables.c b/libio/vtables.c\nindex ca9f1b2dc4..ba3f9566f8 100644\n--- a/libio/vtables.c\n+++ b/libio/vtables.c\n@@ -79,10 +79,12 @@\n # pragma weak _IO_mem_finish\n # pragma weak _IO_mem_setbuf\n # pragma weak _IO_mem_sync\n+# pragma weak _IO_mem_doallocate\n \n # pragma weak _IO_wmem_finish\n # pragma weak _IO_wmem_setbuf\n # pragma weak _IO_wmem_sync\n+# pragma weak _IO_wmem_doallocate\n \n # pragma weak __printf_buffer_as_file_overflow\n # pragma weak __printf_buffer_as_file_xsputn\n@@ -338,7 +340,7 @@ const struct _IO_jump_t __io_vtables[] attribute_relro =\n     JUMP_INIT (seekpos, _IO_default_seekpos),\n     JUMP_INIT (setbuf, _IO_mem_setbuf),\n     JUMP_INIT (sync, _IO_mem_sync),\n-    JUMP_INIT (doallocate, _IO_default_doallocate),\n+    JUMP_INIT (doallocate, _IO_mem_doallocate),\n     JUMP_INIT (read, _IO_default_read),\n     JUMP_INIT (write, _IO_default_write),\n     JUMP_INIT (seek, _IO_default_seek),\n@@ -361,7 +363,7 @@ const struct _IO_jump_t __io_vtables[] attribute_relro =\n     JUMP_INIT (seekpos, _IO_default_seekpos),\n     JUMP_INIT (setbuf, _IO_wmem_setbuf),\n     JUMP_INIT (sync, _IO_wmem_sync),\n-    JUMP_INIT (doallocate, _IO_wdefault_doallocate),\n+    JUMP_INIT (doallocate, _IO_wmem_doallocate),\n     JUMP_INIT (read, _IO_default_read),\n     JUMP_INIT (write, _IO_default_write),\n     JUMP_INIT (seek, _IO_default_seek),\ndiff --git a/libio/wmemstream.c b/libio/wmemstream.c\nindex cdee2a4151..dffbb4a808 100644\n--- a/libio/wmemstream.c\n+++ b/libio/wmemstream.c\n@@ -125,3 +125,12 @@ _IO_wmem_setbuf (FILE *fp, char *p, ssize_t len)\n   /* Wmemstreams manage a growable buffer internally.  */\n   return fp;\n }\n+\n+\n+int\n+_IO_wmem_doallocate (FILE *fp)\n+{\n+  /* Wmemstreams manage a growable buffer internally.  The doallocate\n+     hook must not replace it with a generic stdio buffer.  */\n+  return 1;\n+}\n","prefixes":["v5","2/2"]}