From patchwork Thu Nov 19 06:57:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Sadineni, Harish" X-Patchwork-Id: 104859 X-Patchwork-Delegate: yoann.congal@smile.fr Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.9691.1795071526736275057 for ; Wed, 18 Nov 2026 22:58:47 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="dkim: body hash did not verify" header.i=@windriver.com header.s=PPS06212021 header.b=Qwhg+783; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: windriver.com, ip: 205.220.178.238, mailfrom: prvs=5783957acd=harish.sadineni@windriver.com) Received: from pps.filterd (m0250812.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AJ6v9gs2274493 for ; Thu, 19 Nov 2026 06:58:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriver.com; h=cc:content-transfer-encoding:content-type:date:from :message-id:mime-version:subject:to; s=PPS06212021; bh=KkvGuAm5Y sr50KQIssH8LXOywtukdjzC5Os2JEmra8E=; b=Qwhg+783K+yRVf02lamVGu3Z/ mOgtW+mjIjMQy7G7XC1n4UoELgP+ZLMs6GbF6AkYKD1YNINCgquJcAT2BZUkP3QM 8spQYyMzC8sEQtnNPl3dTYlTaO0lUMDu8pzu4Iy299TW0K0WghNcPRDDIzCtDYAa Q+CigfnUO27N72bsqNIUznS1XptmQ0dE0Gme9aid2iVy3spqcW9lp9OdVRxr3Qd7 IUV2PjgkNuGdEx6e7taSyXRkIkrvYjqMY4XTSSvUYiEnOm+7W7MIvRHPEF9O+tep /ZVKFVLLLXqPxQ3XeALTU32IyqvxK0dsJA4BVfyKMbeziFPCMcifuvcJLp4Yw== Received: from cy7pr03cu001.outbound.protection.outlook.com (mail-westcentralusazon11020125.outbound.protection.outlook.com [40.93.198.125]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 4j0yvh5k06-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 19 Nov 2026 06:58:44 +0000 (GMT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QM7bB5vAFIXvx5oAnqZ9zlY775El4iMt0xPWgqosbaaiVY5cwqv+8scEcP+I3YyyHAEDhMD4wAqhe/iXlAq7+fuhqLDrCz+mA7ymgp0iJZzrY8k+m5jFPZ1yeJmuictZuosEEheHUGdAce8tAzCGPCRnPjysjrxhG490Np2aLcA9ycUUXqgSH6bTzkJIkBkLI70ZH8MWnVL0iXw0w8xdcMabj2b0INeRuGdT8AM8LWt8l+Qn7G1vqrUHcqo1qLaXEf3sVcg4kcmIDx5n5n7bpzce7RMCubXDNpl7zvoNH2gvQ0Pq70ueHnwqlqQV0AezA6plAjsBS9TwRLRlfmoW8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KkvGuAm5Ysr50KQIssH8LXOywtukdjzC5Os2JEmra8E=; b=cKqoz2EuEJPFxvTfQ05zzDulR6wiXtEnAVTSuliM6m87qXRhn4iJCh8bsfuVYvWpDyEF6qiEKi5hmcuwNHFYl+S2jO4lM8ENZ9IWDTQqtouh/arONSBQ9dW5XcTAu2IhLBfrB9ZTnu1a/NMl2wReWafp7b7TMbD6LgOKYx5hI47qMW39DL1hY7XniZWQH0rBLcaFABi/+BfhdaTx6MNmGfdKG+4GPpEeNq7ds3POAl1Qw0RbpSJN1VhzXrSW04L508Ll9vfkLFVBNTY+BSNe6A1YSOLED0eJEmPDA8PezW4UoDIyLuM8/gYYSZuPpBl01RlQUxVB1oiT3s2iV7Q6CQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=windriver.com; Received: from SA3PR11MB346485.namprd11.prod.outlook.com (2603:10b6:806:5a4::14) by CH3PR11MB683941.namprd11.prod.outlook.com (2603:10b6:610:360::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.615.14; Thu, 19 Nov 2026 06:58:41 +0000 Received: from SA3PR11MB346485.namprd11.prod.outlook.com ([fe80::7e79:2dbb:6903:6080]) by SA3PR11MB346485.namprd11.prod.outlook.com ([fe80::7e79:2dbb:6903:6080%6]) with mapi id 15.21.0615.013; Thu, 19 Nov 2026 06:58:40 +0000 From: Harish.Sadineni@windriver.com To: openembedded-core@lists.openembedded.org Cc: Sundeep.kokkonda@Windriver.com Subject: [blacksail][PATCH] gcc: Fix for CVE-2026-125709 Date: Wed, 18 Nov 2026 22:57:18 -0800 Message-ID: <20261119065723.3723895-1-Harish.Sadineni@windriver.com> X-Mailer: git-send-email 2.49.0 X-ClientProxiedBy: BYAPR21CA0014.namprd21.prod.outlook.com (2603:10b6:a03:114::24) To SA3PR11MB346485.namprd11.prod.outlook.com (2603:10b6:806:5a4::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA3PR11MB346485:EE_|CH3PR11MB683941:EE_ X-MS-Office365-Filtering-Correlation-Id: 33a1716b-5d7c-4462-eb61-08df460a8b1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|366016|1800799024|376014|52116014|6133799003|261009223027099003|260925021311599003|18002099003|260925021911599003|260925022911599003|3023799007|261026121527099003|261021121427099003|261028144727099003|261022105027099003|261102123227099003|56012099006|261026140227099003|10067099003|5023799004|38350700014|11063799006; X-Microsoft-Antispam-Message-Info: TAg+bn+kzQlA2hpe5QFhYws6EH2Z8k5jy+RwYDoor5TgUt5bgcXUXJVXBcL1MyISUcxAZQD13WVEf98X8QQH49faNFWaAv5iOd0eT/pAbHPOo1IB2TLE/9c0H6SR6OHHVYHhWjGSPHwQpBVk/5dy2nA4357GrnNHDsFtrxqBqCDFgCbnWxHKGs6ljjGM78TiozrHuH7Ycn1Me4BZVP2c8B3sDGS9pXZ/ZKJiqLVZ3I2hiiQSh6jvlouCLLLp5eNWBAJPF9L35mX9j2sR1Xsmp8IIrr56s1YAvb76vjNgmdkA3PXF64CwCcW3Tr3KqBXpsQ15YDCxBh+CzxSFleJ7y5A9Jpn/ktUQXX2Itfg4FqQF0ltZeeapVUzk5yL8bTlFOqjIwm2MvjlvRyJtTTS7fzwNpbi0+z5uq/WIx8FsjVnEGa0YlEIFGSLdiMH/da8fkkzk0zdc7T6wVqeExSYC+bG3+aBRj++Wo5Bty/1g1is1ZuLVy6lU9NRGxKkS4Pgi9qIXylmRFP6XBBCYiP//hfqQ/fYd7I9iSIdmQk644u7PCpeqQYFWPFklDHWvBs2p5sQnKwmtObQ3anYPIs16JkLY8Eoc73r7jBPKyaEidzncVgGY4D3LpLP/tq5QW83ocKLwCIUa8cOE7rRkUEGEnv7QBzYZ2rEXfo5IMixYwtz4Tzas+naq2A/r/9OKOToXN2ZFv1MdnGifdC5i1HyzZu/goq10sKuYLyKQDx8uiFA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA3PR11MB346485.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(52116014)(6133799003)(261009223027099003)(260925021311599003)(18002099003)(260925021911599003)(260925022911599003)(3023799007)(261026121527099003)(261021121427099003)(261028144727099003)(261022105027099003)(261102123227099003)(56012099006)(261026140227099003)(10067099003)(5023799004)(38350700014)(11063799006);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?NaayEQgT/HdRBprCRGsOquMm3UJx?= =?utf-8?q?pdyWRKuSPF4Q2lMPAtr+dRXShGQ3uj9vZrQqM1zZMdXCENYhAlECyYrop05HhUhqz?= =?utf-8?q?6/fQ68jN6k6FM6mru2SgMn6veFnOvOmt1UWIwMBU0x+D/017pRNuzKj+kJ5MLP+Sw?= =?utf-8?q?kproIXO8hhgN7YqGLkxGhBW+zQBzPVtrsypFMIaPkqj3J6l/1mziL30GVdg7UQlIM?= =?utf-8?q?OpFYBbgB81TQrM5jcQe+w1lGYRW7Z6FnpAfZm7bNu7FkMmk7KzCJEbWKks/Z2CE6/?= =?utf-8?q?oGsLgythMD1E66HkknCL0ZRCBUrHgurgD45j8xgpCQN+gR/Kb/imWhfv8fUUeUlDz?= =?utf-8?q?Ldinmj0Igmq8ITXsl/CVq0OrFhW+Yn4LuxBkiabimdKybj7FnaDDrEVgbul4a2MzO?= =?utf-8?q?GOxqHXI+dmepFyGNffZiZDYmzUrwzQ7R9lIwNTDERcWyiJPBxnTKQnTI1YAupzw1Q?= =?utf-8?q?RO8WknljMTxse+hCXO9M8nFT9/JyLOK/3tGwIfTUPBpgg4PXTtjjVOdlHO79nJE84?= =?utf-8?q?u/1bNxO7WXVpex+FfU6JBos36agz8aEl7SGT17YuJgg/SjYW7uxr1hcHvinV2+uf/?= =?utf-8?q?3a4P4eYD0nOSyvCixvrkHDJPMEymFeDqA92H2wZjc126pGOWsr5eNjAGJzd03aOap?= =?utf-8?q?YQB9UDKcE/QJ+SR1wvx+tO0uBUdgcJ/sdmSrJXc4nu46hFWge17l+83fcCQY1Wo7i?= =?utf-8?q?E8mGiYkIhSGShdVBRGOhTvb0ps79A/yrIIcheaVQ+8+5i7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Rih/un1GaBkX1RxfKQOBR23r?= =?utf-8?q?ZSmTBYAd1MZdSAJIfUrGWeOAypmsLdM1/W2941OHRw9XozAXxigtM=3D?= X-Exchange-RoutingPolicyChecked: YpSCWrK5ynl8QgbIqRvj6K6mHIHMJh6PcHvFMEulnKvsRJCi8t2NXcZT8AF5OGdL/4Gq/1LXfyL0wdDCWmGQDd1mKhRdxLUTn0Pkc3jJZzGNyahRBGjIAtQjmF3Ut7I7W6yGmhtwhuzSXiSj082VY3r1NALWZ9mlILcNDkA9hPCq6J7HBBt7p6w7UafyGl4olP1nuKbQVCvsh3wB9JdyBmtmZrM4DFN4AM+n5XKQv34rUIJZvHDPB55kfceCDDQQYbqUNjvFogWTuYCPMCZCoOY8aL0yD4ZNzWR91GqKD6sfrxN9qJFzl5dvDPSaHOA615BawImMCxpRfiZeh98myg== X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33a1716b-5d7c-4462-eb61-08df460a8b1b X-MS-Exchange-CrossTenant-AuthSource: SA3PR11MB346485.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2026 06:58:40.8222 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 36WO1dPHwoAde1dWWDr8rta0FQqE0gq4+fty306nUwk3pivnOFcDLk2/VpsCYRBtYy7wAhnOM3bio6G5t+W29fuf8FSxV8Z0AJUPlA4NPy8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB683941 X-Proofpoint-GUID: 7fdvKVb7BB75hzhehyaaBpj63rjyiyjo X-Proofpoint-ORIG-GUID: 7fdvKVb7BB75hzhehyaaBpj63rjyiyjo X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE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CeM3EgAAAA:8 a=j5bqmL3JzUQx6YTb6fkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-19_02,2026-11-16_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 spamscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 bulkscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611190027 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-0064b401.pphosted.com id 6AJ6v9gs2274493 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Thu, 19 Nov 2026 06:58:49 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/250652 From: Harish Sadineni libstdc++: Fix buffer overflows in basic_filebuf::overflow [PR118099] If we fail to write the content of the buffer after inserting the overflow character into the end of it, then remove that overflow character before propagating the error back to the caller. Without this, the caller is left with pptr set past epptr, and successive calls to overflow will write further past the end of the managed buffer with each failure. References: https://nvd.nist.gov/vuln/detail/cve-2026-125709 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118099 https://bugzilla.redhat.com/show_bug.cgi?id=2569390 Signed-off-by: Harish Sadineni --- meta/recipes-devtools/gcc/gcc-16.2.inc | 1 + .../gcc/gcc/0027-CVE-2026-125907.patch | 378 ++++++++++++++++++ 2 files changed, 379 insertions(+) create mode 100644 meta/recipes-devtools/gcc/gcc/0027-CVE-2026-125907.patch diff --git a/meta/recipes-devtools/gcc/gcc-16.2.inc b/meta/recipes-devtools/gcc/gcc-16.2.inc index 3497493619..84a6175abe 100644 --- a/meta/recipes-devtools/gcc/gcc-16.2.inc +++ b/meta/recipes-devtools/gcc/gcc-16.2.inc @@ -75,6 +75,7 @@ SRC_URI = "${BASEURI} \ file://0001-mapper-localhost-might-not-be-known.patch \ file://0001-Fix-check-for-working-assembler-gdwarf-4-option.patch \ file://0026-CVE-2026-102010.patch \ + file://0027-CVE-2026-125907.patch \ " UNPACKDIR = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/sources" diff --git a/meta/recipes-devtools/gcc/gcc/0027-CVE-2026-125907.patch b/meta/recipes-devtools/gcc/gcc/0027-CVE-2026-125907.patch new file mode 100644 index 0000000000..cb3a437475 --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc/0027-CVE-2026-125907.patch @@ -0,0 +1,378 @@ +From 68b1b9056c70acb31f2964963b51c480ff820602 Mon Sep 17 00:00:00 2001 +From: Jonathan Wakely +Date: Wed, 28 Oct 2026 10:34:17 +0000 +Subject: libstdc++: Fix buffer overflows in basic_filebuf::overflow [PR118099] +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +If we fail to write the content of the buffer after inserting the +overflow character into the end of it, then remove that overflow +character before propagating the error back to the caller. Without this, +the caller is left with pptr set past epptr, and successive calls to +overflow will write further past the end of the managed buffer with each +failure. + +The new 118099-codecvt.cc tests were assisted by an LLM because I was +too lazy to remember how to write codecvt facets. + +Assisted-by: LLM + +libstdc++-v3/ChangeLog: + + PR libstdc++/118099 + * include/bits/fstream.tcc (basic_filebuf::overflow): Rewind the + put position if outputting the put area fails. + * testsuite/27_io/basic_filebuf/overflow/char/118099-codecvt.cc: + New test. + * testsuite/27_io/basic_filebuf/overflow/char/118099.cc: New + test. + * testsuite/27_io/basic_filebuf/overflow/wchar_t/118099-codecvt.cc: + New test. + * testsuite/27_io/basic_filebuf/overflow/wchar_t/118099.cc: + New test. + +CVE: CVE-2026-125709 + +Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/commit/?id=68b1b9056c70acb31f2964963b51c480ff820602] + +Signed-off-by: Harish Sadineni + +Reviewed-by: Tomasz KamiƄski +(cherry picked from commit 2d296e9f024edbb49cad1f3ebb5ae34c71ea5f7a) +--- + libstdc++-v3/include/bits/fstream.tcc | 8 +++ + .../basic_filebuf/overflow/char/118099-codecvt.cc | 76 ++++++++++++++++++++++ + .../27_io/basic_filebuf/overflow/char/118099.cc | 57 ++++++++++++++++ + .../overflow/wchar_t/118099-codecvt.cc | 76 ++++++++++++++++++++++ + .../27_io/basic_filebuf/overflow/wchar_t/118099.cc | 57 ++++++++++++++++ + 5 files changed, 274 insertions(+) + create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099-codecvt.cc + create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099.cc + create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099-codecvt.cc + create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099.cc + +diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc +index 99aa296b83c4..0d1d9491cb6a 100644 +--- a/libstdc++-v3/include/bits/fstream.tcc ++++ b/libstdc++-v3/include/bits/fstream.tcc +@@ -561,11 +561,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION + } + if (this->pbase() < this->pptr()) + { ++ struct _Guard { ++ ~_Guard() { if (_M_p) _M_p->pbump(-1); } ++ basic_filebuf* _M_p; ++ }; ++ _Guard __g = { }; ++ + // If appropriate, append the overflow char. + if (!__testeof) + { + *this->pptr() = traits_type::to_char_type(__c); + this->pbump(1); ++ __g._M_p = this; + } + + // Convert pending sequence to external representation, +@@ -573,6 +580,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION + if (_M_convert_to_external(this->pbase(), + this->pptr() - this->pbase())) + { ++ __g._M_p = 0; + _M_set_buffer(0); + __ret = traits_type::not_eof(__c); + } +diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099-codecvt.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099-codecvt.cc +new file mode 100644 +index 000000000000..e4b1106b9b8d +--- /dev/null ++++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099-codecvt.cc +@@ -0,0 +1,76 @@ ++// { dg-do run } ++// { dg-require-fileio "" } ++ ++// PR libstdc++/118099 ++// basic_filebuf::overflow leaves streambuf in inconsistent state on I/O error ++// ++// Companion test of 118099.cc testing the throwing failure path in overflow: ++// a codecvt whose do_out always returns error makes _M_convert_to_external ++// throw after the overflow character has been written to the end of put area. ++// If the put pointer is advanced before the throw (and only rewound on the ++// non-throwing error path), a caller that catches the exception and keeps ++// writing will cause overflow(c) to write past the end of the managed buffer, ++// just like the original PR libstdc++/118099 testcase. ++ ++#include ++#include ++#include ++ ++typedef char C; ++ ++struct failing_codecvt : std::codecvt ++{ ++protected: ++ result ++ do_out(state_type&, const intern_type* from, const intern_type*, ++ const intern_type*& from_next, ++ extern_type* to, extern_type*, extern_type*& to_next) const ++ { ++ from_next = from; ++ to_next = to; ++ return error; ++ } ++ ++ bool do_always_noconv() const throw() { return false; } ++}; ++ ++static void ++test_pr118099_codecvt() ++{ ++ const C val = C('x'); ++ const C canary = ~val; ++ const int N = 8; ++ C buf[N * 2]; ++ for (int i = 0; i < N * 2; ++i) ++ buf[i] = canary; ++ ++ std::basic_filebuf fb; ++ fb.pubimbue(std::locale(std::locale::classic(), new failing_codecvt)); ++ fb.pubsetbuf(buf, N); // filebuf can use buf[0..N] ++ fb.open("tmp_118099_codecvt", std::ios_base::out | std::ios_base::trunc); ++ VERIFY( fb.is_open() ); ++ ++ // Libstdc++ filebuf throws ios::failure for the codecvt error, ++ // but the standard allows overflow to return eof instead. ++ // To make this test portable, we check for either kind of error. ++ bool got_error = false; ++ for (int i = 0; i < N * 2; ++i) ++ try { ++ std::char_traits::int_type r = fb.sputc(val); ++ if (std::char_traits::eq_int_type(r, std::char_traits::eof())) ++ got_error = true; ++ } catch (const std::exception&) { ++ got_error = true; ++ } ++ VERIFY( got_error ); // a codecvt error actually happened ++ ++ for (int i = 0; i < N; ++i) ++ VERIFY( buf[i] == val ); ++ for (int i = N; i < N * 2; ++i) ++ VERIFY( buf[i] == canary ); // nothing was written past buf[0..N] ++} ++ ++int main() ++{ ++ test_pr118099_codecvt(); ++} +diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099.cc +new file mode 100644 +index 000000000000..2407119dcb1b +--- /dev/null ++++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/118099.cc +@@ -0,0 +1,57 @@ ++// { dg-do run } ++// { dg-require-fileio "" } ++ ++// PR libstdc++/118099 ++// basic_filebuf::overflow leaves streambuf in inconsistent state on I/O error ++ ++#include ++#include ++ ++static void ++test_pr118099() ++{ ++ typedef char C; ++ ++ // Only run if /dev/full already exists as a device: probe it with a ++ // read-only open first, so we never accidentally create a regular file ++ // named /dev/full on a hypothetical system with a writable /dev. ++ { ++ std::filebuf probe; ++ if (!probe.open("/dev/full", std::ios_base::in)) ++ return; // no /dev/full here: nothing to test. ++ } ++ ++ const C val = C('x'); ++ const C canary = ~val; ++ const int N = 8; ++ C buf[N * 2] = { }; ++ for (int i = 0; i < N * 2; ++i) ++ buf[i] = canary; ++ ++ std::basic_filebuf fb; ++ fb.pubsetbuf(buf, N); // filebuf can use buf[0..N] ++ fb.open("/dev/full", std::ios_base::out); ++ VERIFY( fb.is_open() ); ++ ++ int i = 0; ++ // Keep writing until overflow happens (and fails): ++ while (fb.sputc(val) != std::char_traits::eof()) ++ ++i; ++ // There should have been N-1 successful calls before overflow failed: ++ VERIFY( i == (N - 1) ); ++ // Overflow some more: ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ ++ // Verify that only the first N positions in the buffer were changed: ++ for (i = 0; i < N; ++i) ++ VERIFY( buf[i] == val ); ++ for (; i < N * 2; ++i) ++ VERIFY( buf[i] == canary ); ++} ++ ++int main() ++{ ++ test_pr118099(); ++} +diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099-codecvt.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099-codecvt.cc +new file mode 100644 +index 000000000000..add23cc99500 +--- /dev/null ++++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099-codecvt.cc +@@ -0,0 +1,76 @@ ++// { dg-do run } ++// { dg-require-fileio "" } ++ ++// PR libstdc++/118099 ++// basic_filebuf::overflow leaves streambuf in inconsistent state on I/O error ++// ++// Companion test of 118099.cc testing the throwing failure path in overflow: ++// a codecvt whose do_out always returns error makes _M_convert_to_external ++// throw after the overflow character has been written to the end of put area. ++// If the put pointer is advanced before the throw (and only rewound on the ++// non-throwing error path), a caller that catches the exception and keeps ++// writing will cause overflow(c) to write past the end of the managed buffer, ++// just like the original PR libstdc++/118099 testcase. ++ ++#include ++#include ++#include ++ ++typedef wchar_t C; ++ ++struct failing_codecvt : std::codecvt ++{ ++protected: ++ result ++ do_out(state_type&, const intern_type* from, const intern_type*, ++ const intern_type*& from_next, ++ extern_type* to, extern_type*, extern_type*& to_next) const ++ { ++ from_next = from; ++ to_next = to; ++ return error; ++ } ++ ++ bool do_always_noconv() const throw() { return false; } ++}; ++ ++static void ++test_pr118099_codecvt() ++{ ++ const C val = C('x'); ++ const C canary = ~val; ++ const int N = 8; ++ C buf[N * 2]; ++ for (int i = 0; i < N * 2; ++i) ++ buf[i] = canary; ++ ++ std::basic_filebuf fb; ++ fb.pubimbue(std::locale(std::locale::classic(), new failing_codecvt)); ++ fb.pubsetbuf(buf, N); // filebuf can use buf[0..N] ++ fb.open("tmp_118099_codecvt", std::ios_base::out | std::ios_base::trunc); ++ VERIFY( fb.is_open() ); ++ ++ // Libstdc++ filebuf throws ios::failure for the codecvt error, ++ // but the standard allows overflow to return eof instead. ++ // To make this test portable, we check for either kind of error. ++ bool got_error = false; ++ for (int i = 0; i < N * 2; ++i) ++ try { ++ std::char_traits::int_type r = fb.sputc(val); ++ if (std::char_traits::eq_int_type(r, std::char_traits::eof())) ++ got_error = true; ++ } catch (const std::exception&) { ++ got_error = true; ++ } ++ VERIFY( got_error ); // a codecvt error actually happened ++ ++ for (int i = 0; i < N; ++i) ++ VERIFY( buf[i] == val ); ++ for (int i = N; i < N * 2; ++i) ++ VERIFY( buf[i] == canary ); // nothing was written past buf[0..N] ++} ++ ++int main() ++{ ++ test_pr118099_codecvt(); ++} +diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099.cc +new file mode 100644 +index 000000000000..bcbbd58ee9c1 +--- /dev/null ++++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/118099.cc +@@ -0,0 +1,57 @@ ++// { dg-do run } ++// { dg-require-fileio "" } ++ ++// PR libstdc++/118099 ++// basic_filebuf::overflow leaves streambuf in inconsistent state on I/O error ++ ++#include ++#include ++ ++static void ++test_pr118099() ++{ ++ typedef wchar_t C; ++ ++ // Only run if /dev/full already exists as a device: probe it with a ++ // read-only open first, so we never accidentally create a regular file ++ // named /dev/full on a hypothetical system with a writable /dev. ++ { ++ std::filebuf probe; ++ if (!probe.open("/dev/full", std::ios_base::in)) ++ return; // no /dev/full here: nothing to test. ++ } ++ ++ const C val = C('x'); ++ const C canary = ~val; ++ const int N = 8; ++ C buf[N * 2] = { }; ++ for (int i = 0; i < N * 2; ++i) ++ buf[i] = canary; ++ ++ std::basic_filebuf fb; ++ fb.pubsetbuf(buf, N); // filebuf can use buf[0..N] ++ fb.open("/dev/full", std::ios_base::out); ++ VERIFY( fb.is_open() ); ++ ++ int i = 0; ++ // Keep writing until overflow happens (and fails): ++ while (fb.sputc(val) != std::char_traits::eof()) ++ ++i; ++ // There should have been N-1 successful calls before overflow failed: ++ VERIFY( i == (N - 1) ); ++ // Cause some more calls to overflow, which should also fail: ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ VERIFY( fb.sputc(val) == std::char_traits::eof() ); ++ ++ // Verify that only the first N positions in the buffer were changed: ++ for (i = 0; i < N; ++i) ++ VERIFY( buf[i] == val ); ++ for (; i < N * 2; ++i) ++ VERIFY( buf[i] == canary ); ++} ++ ++int main() ++{ ++ test_pr118099(); ++} +-- +cgit +