Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2232540/?format=api
{ "id": 2232540, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2232540/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/patch/20260504172206.2470310-2-avinal.xlvii@gmail.com/", "project": { "id": 41, "url": "http://patchwork.ozlabs.org/api/1.1/projects/41/?format=api", "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": "" }, "msgid": "<20260504172206.2470310-2-avinal.xlvii@gmail.com>", "date": "2026-05-04T17:22:06", "name": "[v3,2/2] intl: Add tests for plural expression hardening", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "93d4c9fe04964c59086163bf57248dd95ec83258", "submitter": { "id": 88549, "url": "http://patchwork.ozlabs.org/api/1.1/people/88549/?format=api", "name": "Avinal Kumar", "email": "avinal.xlvii@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/glibc/patch/20260504172206.2470310-2-avinal.xlvii@gmail.com/mbox/", "series": [ { "id": 502702, "url": "http://patchwork.ozlabs.org/api/1.1/series/502702/?format=api", "web_url": "http://patchwork.ozlabs.org/project/glibc/list/?series=502702", "date": "2026-05-04T17:22:05", "name": "[v3,1/2] intl: Import plural expression hardening from GNU gettext", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/502702/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2232540/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2232540/checks/", "tags": {}, "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\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=mC9LQltQ;\n\tdkim-atps=neutral", "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\tdkim=pass (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=mC9LQltQ", "sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com", "sourceware.org; spf=pass smtp.mailfrom=gmail.com", "server2.sourceware.org;\n arc=none smtp.remote-ip=2607:f8b0:4864:20::1036" ], "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 4g8T5h3HSDz1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 05 May 2026 03:24:08 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 73B734B9DB7E\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 4 May 2026 17:24:06 +0000 (GMT)", "from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com\n [IPv6:2607:f8b0:4864:20::1036])\n by sourceware.org (Postfix) with ESMTPS id 642DA4BAD15A\n for <libc-alpha@sourceware.org>; Mon, 4 May 2026 17:22:27 +0000 (GMT)", "by mail-pj1-x1036.google.com with SMTP id\n 98e67ed59e1d1-36505450d0dso2673925a91.1\n for <libc-alpha@sourceware.org>; Mon, 04 May 2026 10:22:27 -0700 (PDT)", "from fedoraemon.neon-universe.ts.net\n ([2406:7400:11d:a9dc:9a14:72eb:1a60:868a])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b9cae36885sm114138955ad.59.2026.05.04.10.22.23\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Mon, 04 May 2026 10:22:24 -0700 (PDT)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 73B734B9DB7E", "OpenDKIM Filter v2.11.0 sourceware.org 642DA4BAD15A" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 642DA4BAD15A", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 642DA4BAD15A", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777915347; cv=none;\n b=CAmbYZ3FLzNZM682qP4uMmrLl9xP4fnN7OzUBUDZm4ixAF9eOMNCkVX6IwS9nlrcmP35vG1zYU/Cfa54SCPmUMIu2I95qTJbuKUv1mJhfGitOfCufKZfn/vkQBkz0FPoyMhe9WY+Af5+XsJqkW2+qlrRs31E1G8XBpNQBefN3aM=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777915347; c=relaxed/simple;\n bh=tUCLeg65kNw/TMIA1YFMpJmGOANj8iD23i54GVA55vc=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=LbXkvHloJDOshJ4cKFT+msY4StYX6ERPcmNg2L/kNSetLmUAs8i7TBeqWapIYnRUbeMR2UlCet06OH9rd869AU5BBr9RnL2dFWo4EkaHrEMDCZiwCgp/mrJsoEXw3gMAzjHiHAtu4ewJkYmPB/iV93P6FmTc/GPFQC3KdJVFOgs=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1777915346; x=1778520146; darn=sourceware.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ZbrPEz+b8go3gNumMHVgmMc2MOqNSHXS6xzNKh3tW4s=;\n b=mC9LQltQFlmvnJuKhUb/HNx48cV4S78s1lj3AgLkdzLqgzRCY9ZxE+zsnXPdBLic80\n p22Otyr1ZBUCivtSJwG/mjA42ErtduQ3+YeyR1L8x/0wR6ooOkL0ireSWPR7RjFwk7sw\n HiwMmPzonWMildISRLgYsmJq6rGgRFipXx4uY4VhKihV3hsHCGOyZqllgXuBYFQGKm8c\n si7jVNNu+j4tr6XRX+Dt1n/pkFhKSvvmS2/h8kD3N36iR6LpOSi/7zPwI13/viv2GOaM\n Jb2OKD+/JL2JK8rkaAbX815o9ix99EY2iIGLhx2k8PUZ6FlMbliFHq8t0bJU+8/x3270\n PtYQ==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777915346; x=1778520146;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ZbrPEz+b8go3gNumMHVgmMc2MOqNSHXS6xzNKh3tW4s=;\n b=ZwMD5LJz2CXGwsWdNW4VkbqH1xZt4P9thCoLq3no87aQXrh27AbXgVQR5ZAio3ov5C\n 7x9QkBWDN9p3yrDBVoFw+UAicn9HPme4phhlRbszHBSB2L4bHFVr8KTVh4tLajobvHz3\n zHEfgcDhxEL1ZMOiHwSn2eOFfJsvx+GC3Gf8MZmDnvdANZp0OmPZqtizmdutX2rUdpBh\n 2Dq9GfU/u+3V35ft9FQzkoW7CmGQdI2laKF0X0EIlIEAoFDP+/wjvN2sPAlpTGfU4FtU\n odSCZt1WfIoN1KuDk8GMqKUsS3Dg7xk/hSGW5vZ6gaXcKbnsninHDaBOudAeYQH/knKI\n 3FsA==", "X-Gm-Message-State": "AOJu0YwB6hQua6PKtXOTDCdlw/8C8RIOmKnMg9/IQ12bjfS2DzjqMOY5\n zjWTwgPyPOTlrJhkiwgi07kV+n33QzvNDXZhQpiXz/Lex8d6JTGhJhdRNVJBjw==", "X-Gm-Gg": "AeBDieui/wJ5A06TNEkqLy2Wc5135lBLcc5qbAEw7sftVWihwxYsGnaab9+giXVU2Fg\n rtkr7DSEJUcW+A4/qRBGkoaxDLR+1300R0/wqHNckKabNITVh4x/Y55nDDby8s8zIdTghnOph87\n 6tTDWfR/LnKSrAO9vSV12LQHa129Zlj6llDVHmwiQ2xucVKhBiT470AvZlOCIn5hW2ZkSzibgXC\n EZj9SWOmx09+KS9RYHpx+PiNSsLYap06yi0xdemeJ+TFEuQwXVrch8yabWtcP8beZDbJG6nvRj5\n wltGYzO0AngnY8TiCftn3DzwNzlGPVBthC62r06Lgw4xcvPol//ICQRqUtefUTvemH3HVJ2DHgo\n 921DhmSOmjIvtR42/XOSHHtA3fWTaim+jZlpforisqdRAU8uqrLiMcE/+EpjlFvY/Rs16Z2Uqd3\n t7HMb910t9y+DsS3NCzFBTIK6fYduk7wD8HADp6vl8wRk/kMwiE6cHjnS4tFdWZEuNiw==", "X-Received": "by 2002:a17:90b:2f86:b0:35b:e593:b1d7 with SMTP id\n 98e67ed59e1d1-3650cdda08emr10127444a91.12.1777915345717;\n Mon, 04 May 2026 10:22:25 -0700 (PDT)", "From": "Avinal Kumar <avinal.xlvii@gmail.com>", "To": "libc-alpha@sourceware.org", "Cc": "adhemerval.zanella@linaro.org", "Subject": "[PATCH v3 2/2] intl: Add tests for plural expression hardening", "Date": "Mon, 4 May 2026 22:52:06 +0530", "Message-ID": "<20260504172206.2470310-2-avinal.xlvii@gmail.com>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260504172206.2470310-1-avinal.xlvii@gmail.com>", "References": "<20260504172206.2470310-1-avinal.xlvii@gmail.com>", "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": "The first test checks for stack overflow. It uses a plural expression\nnested 5000 levels deep using the !(1-(...)) pattern. The parser\naccepts it (below YYMAXDEPTH=10000), but evaluation exeeds\nEVAL_MAXDEPTH=100 and falls back to index 0 instead of crashing with\nSIGSEGV.\n\nThe second test checks for division by zero in plural expression. The\nexpression (n!=1)+1/(n!=1729) triggers 1/0 for n=1729. msgfmt only\nvalidates 0<= n <= 1000, so the .mo file is accepted. Evaluation\nreturns PE_INTDIV and falls back instead of raising SIGFPE.\n\nAdaptations from gettext to glibc:\n\n- gettext's plural-3 embeds the nested expresion as a literal string.\nThis test uses an AWK script (plural-depth.awk) to generate the same\nexpression.\n\n- gettext uses LANGUAGE= (empty) with LC_ALL=ll and its own locale\nsetup. glibc requires a real locale for setlocale() or else the \"C\"\nlocale override in dcigettext.c ignores LANGUAGE entirely.\n\nThe tests are derived from GNU gettext's plural-3 (commit 021348871a22)\nand plural-4 (commit 429ba6c6b835), adapted to glibc's test framework.\n\nOriginal author: Bruno Haible <bruno@clisp.org>\nSigned-off-by: Avinal Kumar <avinal.xlvii@gmail.com>\n---\nChanges from v2:\n- Use TEST_VERIFY\n- Style changes in Makefile\n- Typo fixed in commit message\n\n intl/Makefile | 32 +++++++++++++----\n intl/plural-depth.awk | 54 +++++++++++++++++++++++++++++\n intl/tst-plural-eval.c | 76 +++++++++++++++++++++++++++++++++++++++++\n intl/tst-plural-eval.sh | 67 ++++++++++++++++++++++++++++++++++++\n 4 files changed, 223 insertions(+), 6 deletions(-)\n create mode 100644 intl/plural-depth.awk\n create mode 100644 intl/tst-plural-eval.c\n create mode 100644 intl/tst-plural-eval.sh", "diff": "diff --git a/intl/Makefile b/intl/Makefile\nindex 42875eb1a9..a8b41a1993 100644\n--- a/intl/Makefile\n+++ b/intl/Makefile\n@@ -22,13 +22,21 @@ subdir = intl\n include ../Makeconfig\n \n headers = libintl.h\n-routines = bindtextdom dcgettext dgettext gettext\t\\\n+routines = bindtextdom dcgettext dgettext gettext \\\n \t dcigettext dcngettext dngettext ngettext \\\n \t finddomain loadmsgcat localealias textdomain\n-aux =\t l10nflist explodename plural plural-exp hash-string\n+aux = l10nflist explodename plural plural-exp hash-string\n \n multithread-test-srcs := tst-gettext4 tst-gettext5 tst-gettext6\n-test-srcs := tst-gettext tst-translit tst-gettext2 tst-codeset tst-gettext3\n+test-srcs := \\\n+\ttst-gettext \\\n+\ttst-translit \\\n+\ttst-gettext2 \\\n+\ttst-codeset \\\n+\ttst-gettext3 \\\n+\ttst-plural-eval\n+\t# test-srcs\n+\n ifeq ($(have-thread-library),yes)\n test-srcs += $(multithread-test-srcs)\n endif\n@@ -53,9 +61,15 @@ $(objpfx)plural.o: $(objpfx)plural.c\n ifeq ($(run-built-tests),yes)\n ifeq (yes,$(build-shared))\n ifneq ($(strip $(MSGFMT)),:)\n-tests-special += $(objpfx)tst-translit.out $(objpfx)tst-gettext.out \\\n-\t\t $(objpfx)tst-gettext2.out $(objpfx)tst-codeset.out \\\n-\t\t $(objpfx)tst-gettext3.out\n+tests-special += \\\n+\t$(objpfx)tst-translit.out \\\n+\t$(objpfx)tst-gettext.out \\\n+\t$(objpfx)tst-gettext2.out \\\n+\t$(objpfx)tst-codeset.out \\\n+\t$(objpfx)tst-gettext3.out \\\n+\t$(objpfx)tst-plural-eval.out\n+\t# tests-special\n+\n ifeq ($(have-thread-library),yes)\n tests-special += $(objpfx)tst-gettext4.out $(objpfx)tst-gettext5.out \\\n \t\t $(objpfx)tst-gettext6.out\n@@ -103,6 +117,10 @@ $(objpfx)tst-gettext4.out: tst-gettext4.sh $(objpfx)tst-gettext4\n $(objpfx)tst-gettext6.out: tst-gettext6.sh $(objpfx)tst-gettext6\n \t$(SHELL) $< $(common-objpfx) '$(test-program-prefix)' $(common-objpfx)intl/; \\\n \t$(evaluate-test)\n+$(objpfx)tst-plural-eval.out: tst-plural-eval.sh $(objpfx)tst-plural-eval\n+\t$(SHELL) $< $(common-objpfx) '$(test-program-prefix)' \\\n+\t $(common-objpfx)intl/; \\\n+\t$(evaluate-test)\n \n $(objpfx)tst-codeset.out: $(codeset_mo)\n $(objpfx)tst-gettext3.out: $(codeset_mo)\n@@ -140,6 +158,7 @@ CFLAGS-tst-gettext3.c += -DOBJPFX=\\\"$(objpfx)\\\"\n CFLAGS-tst-gettext4.c += -DOBJPFX=\\\"$(objpfx)\\\"\n CFLAGS-tst-gettext5.c += -DOBJPFX=\\\"$(objpfx)\\\"\n CFLAGS-tst-gettext6.c += -DOBJPFX=\\\"$(objpfx)\\\"\n+CFLAGS-tst-plural-eval.c += -DOBJPFX=\\\"$(objpfx)\\\"\n \n ifeq ($(have-thread-library),yes)\n ifeq (yes,$(build-shared))\n@@ -156,6 +175,7 @@ $(objpfx)tst-gettext3.out: $(objpfx)tst-gettext.out\n $(objpfx)tst-gettext4.out: $(objpfx)tst-gettext.out\n $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out\n $(objpfx)tst-gettext6.out: $(objpfx)tst-gettext.out\n+$(objpfx)tst-plural-eval.out: $(objpfx)tst-gettext.out\n \n CPPFLAGS += -D'LOCALEDIR=\"$(localedir)\"' \\\n \t -D'LOCALE_ALIAS_PATH=\"$(localedir)\"' \\\ndiff --git a/intl/plural-depth.awk b/intl/plural-depth.awk\nnew file mode 100644\nindex 0000000000..7b200c00e9\n--- /dev/null\n+++ b/intl/plural-depth.awk\n@@ -0,0 +1,54 @@\n+# plural-depth.awk - Generate .po file with deeply nested plural expression.\n+# Copyright (C) 2026 Free Software Foundation, Inc.\n+#\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+# Generate a .po file whose Plural-Forms header contains a plural\n+# expression nested DEPTH levels deep. Each level wraps as !(1-(...)),\n+# producing an expression that is accepted by the parser (YYMAXDEPTH=10000)\n+# but exceeds EVAL_MAXDEPTH=100 at runtime.\n+#\n+# Usage: awk -v DEPTH=5000 -f plural-depth.awk > plural-depth.po\n+\n+BEGIN {\n+ if (DEPTH == 0)\n+\tDEPTH = 5000\n+\n+ expr = \"\"\n+ for (i = 0; i < DEPTH; i++)\n+\texpr = expr \"!(1-\"\n+ expr = expr \"(n!=1)\"\n+ for (i = 0; i < DEPTH; i++)\n+\texpr = expr \")\"\n+\n+ print \"msgid \\\"\\\"\"\n+ print \"msgstr \\\"\\\"\"\n+ print \"\\\"Project-Id-Version: test\\\\n\\\"\"\n+ print \"\\\"PO-Revision-Date: 2026-01-01 00:00+0000\\\\n\\\"\"\n+ print \"\\\"Last-Translator: \\\\n\\\"\"\n+ print \"\\\"Language-Team: \\\\n\\\"\"\n+ print \"\\\"Language: ll\\\\n\\\"\"\n+ print \"\\\"MIME-Version: 1.0\\\\n\\\"\"\n+ print \"\\\"Content-Type: text/plain; charset=ASCII\\\\n\\\"\"\n+ print \"\\\"Content-Transfer-Encoding: 8bit\\\\n\\\"\"\n+ print \"\\\"Plural-Forms: nplurals=2; plural=\" expr \";\\\\n\\\"\"\n+ print \"\"\n+ print \"msgid \\\"X\\\"\"\n+ print \"msgid_plural \\\"Y\\\"\"\n+ print \"msgstr[0] \\\"x\\\"\"\n+ print \"msgstr[1] \\\"y\\\"\"\n+}\ndiff --git a/intl/tst-plural-eval.c b/intl/tst-plural-eval.c\nnew file mode 100644\nindex 0000000000..8658598330\n--- /dev/null\n+++ b/intl/tst-plural-eval.c\n@@ -0,0 +1,76 @@\n+/* Test plural expression evaluation hardening.\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 <libintl.h>\n+#include <locale.h>\n+#include <stdio.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <support/check.h>\n+#include <support/support.h>\n+\n+static int\n+do_test (void)\n+{\n+ unsetenv (\"OUTPUT_CHARSET\");\n+\n+ /* Use a real locale so that the active locale is not \"C\". */\n+ TEST_VERIFY (setenv (\"LC_ALL\", \"de_DE.UTF-8\", 1) == 0);\n+ xsetlocale (LC_ALL, \"\");\n+ /* Set a dummy langauge to override lookup. */\n+ TEST_VERIFY (setenv (\"LANGUAGE\", \"ll\", 1) == 0);\n+\n+ /* Test 1: Stack overflow in plural evaluation.\n+ The .mo file has a plural expression with 5000 levels of nesting\n+ like !(1-(!(1-(...(n!=1)...)))). Before the fix, plural_eval()\n+ used unbounded recursion and would crash with SIGSEGV on threads\n+ with small stacks. After the fix, EVAL_MAXDEPTH=100 causes\n+ plural_eval_recurse() to return PE_STACKOVF, and plural_lookup()\n+ falls back to index 0 (the singular form). */\n+\n+ TEST_VERIFY (bindtextdomain (\"plural-depth\", OBJPFX \"domaindir\") != NULL);\n+ TEST_VERIFY (textdomain (\"plural-depth\") != NULL);\n+\n+ /* ngettext must not crash. The return value depends on whether\n+ the depth limit is hit (falls back to index 0) or the expression\n+ evaluates successfully. Either result is acceptable. */\n+\n+ const char *tr = ngettext (\"X\", \"Y\", 42);\n+ TEST_VERIFY (tr != NULL);\n+ TEST_VERIFY (strcmp (tr, \"x\") == 0 || strcmp (tr, \"y\") == 0);\n+\n+ /* Test 2: Division by zero in plural evaluation.\n+ The .mo file has plural expression (n!=1)+1/(n!=1729).\n+ For n=1729, (n!=1729) is 0, so 1/0 triggers division by zero.\n+ Before the fix, this raised SIGFPE. After the fix,\n+ plural_eval_recurse() returns PE_INTDIV, and plural_lookup()\n+ falls back to index 0. */\n+\n+ TEST_VERIFY (bindtextdomain (\"plural-divzero\", OBJPFX \"domaindir\") != NULL);\n+ TEST_VERIFY (textdomain (\"plural-divzero\") != NULL);\n+\n+ /* ngettext with n=1729 must not crash with SIGFPE. */\n+ tr = ngettext (\"X\", \"Y\", 1729);\n+ TEST_VERIFY (tr != NULL);\n+ TEST_VERIFY (strcmp (tr, \"x\") == 0 || strcmp (tr, \"y\") == 0\n+\t || strcmp (tr, \"z\") == 0);\n+\n+ return 0;\n+}\n+\n+#include <support/test-driver.c>\ndiff --git a/intl/tst-plural-eval.sh b/intl/tst-plural-eval.sh\nnew file mode 100644\nindex 0000000000..f020fa9925\n--- /dev/null\n+++ b/intl/tst-plural-eval.sh\n@@ -0,0 +1,67 @@\n+#!/bin/sh\n+# Test plural expression evaluation hardening.\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+set -e\n+\n+common_objpfx=$1\n+test_program_prefix=$2\n+objpfx=$3\n+\n+# Create domain directories.\n+mkdir -p ${objpfx}domaindir/ll/LC_MESSAGES\n+\n+# Test 1: Deeply nested plural expression (stack overflow test).\n+# This expression has 5000 levels of nesting, well above EVAL_MAXDEPTH=100\n+# but below YYMAXDEPTH=10000 so the parser accepts it.\n+LC_ALL=C awk -v DEPTH=5000 -f plural-depth.awk > ${objpfx}plural-depth.po\n+\n+msgfmt -o ${objpfx}domaindir/ll/LC_MESSAGES/plural-depth.mo \\\n+ ${objpfx}plural-depth.po || exit 1\n+\n+# Test 2: Division by zero in plural expression (SIGFPE test).\n+# The expression 1/(n!=1729) triggers division by zero for n=1729.\n+# msgfmt -c only checks 0 <= n <= 1000, so this passes validation.\n+cat > ${objpfx}plural-divzero.po <<EOF\n+msgid \"\"\n+msgstr \"\"\n+\"Project-Id-Version: test\\n\"\n+\"PO-Revision-Date: 2026-01-01 00:00+0000\\n\"\n+\"Last-Translator: \\n\"\n+\"Language-Team: \\n\"\n+\"Language: ll\\n\"\n+\"MIME-Version: 1.0\\n\"\n+\"Content-Type: text/plain; charset=ASCII\\n\"\n+\"Content-Transfer-Encoding: 8bit\\n\"\n+\"Plural-Forms: nplurals=3; plural=(n!=1)+1/(n!=1729);\\n\"\n+\n+msgid \"X\"\n+msgid_plural \"Y\"\n+msgstr[0] \"x\"\n+msgstr[1] \"y\"\n+msgstr[2] \"z\"\n+EOF\n+\n+msgfmt -o ${objpfx}domaindir/ll/LC_MESSAGES/plural-divzero.mo \\\n+ ${objpfx}plural-divzero.po || exit 1\n+\n+# Run the test.\n+${test_program_prefix} \\\n+${objpfx}tst-plural-eval ${objpfx}domaindir\n+\n+exit $?\n", "prefixes": [ "v3", "2/2" ] }