From patchwork Tue Feb 20 20:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1901670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=rcKb19rM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TfVkn4SNhz23cl for ; Wed, 21 Feb 2024 07:05:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B96A3858C54 for ; Tue, 20 Feb 2024 20:05:19 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id A5E143858D20 for ; Tue, 20 Feb 2024 20:04:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A5E143858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A5E143858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1034 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708459498; cv=none; b=tVjs6a6mgEIvMmG6IFKqX6VO5WbFaQJHXFa5TtjUYCL2ZpaKZmiMCVpLDxeb26lHriIsQpspYOiemh/MogZ6BTBozhboAOMJABrw7GZO1tCxGvtC7iHegvGAjVVzwvwBul9q9/tvrJlDTDD8+B4mrj/q1FqaS+lsL6SIG7UxEKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708459498; c=relaxed/simple; bh=EgAvWCUfk+MQ/ArhPspbnjU1zdyGdn57Zry8d6U5Vi8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BNKkn5iJU3BuBfIPZmGAuAyewxCi/Fb4T92NXGhgnYKO0JqWFoy1UV0JJ02Rxw1muFVYQD6AXj847ZJum62leEOzlKWOnpZ3dtgqmdlt/IDOKwdsRwloXUYaTujaqFsM0c4UyMWUoAc0x3xFPXMtbJvq7FSB6bWNFbLRWGdRzZ8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2906773c7e9so3804972a91.1 for ; Tue, 20 Feb 2024 12:04:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708459490; x=1709064290; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=WkYpRZC1AWS8hNZx0ZmjofK69UUPnpa25EBXQZqlPic=; b=rcKb19rM6o80KbVThpUUEF/8EtJ1ydidfrux3ec/yo2IvIewlSrxR/vJX0SVrdBZAt 6rExN6rl0AE9ZJMm/Ns8LEnPxpNQUiXoKh8irzsz7X7AL2I2sJXwVhazbY8QpdCqEfRM yKjf2atO6LGihD1a4PxAVtiB+nVj50dkJbcPxw0Kzorl2g9mEUcy1+CZJuB4Ts3H7tqI iAOSaLxRq+Szb9A23PkkD/CEvgGMwDjivaAnuTHodbFAIEBT05Wzgm8cwaxMxmWVJ7OK d0M1uX99C4z7eZ27j9D2wVc0xcqWa+cq4VpPyWTJtIgbMENNKCekJoQlF+prqP5gQj1s tCoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708459490; x=1709064290; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WkYpRZC1AWS8hNZx0ZmjofK69UUPnpa25EBXQZqlPic=; b=ZrcFCkAOe5E2gVPA+oiWKhx7OdQauxmn7Vf32C+BRty+wBBNVPEJrvLdaJDcLgSSv/ idFubcP7g2drQ2YV9pItSEkrQN8Jytm0IIzXr5W6EuzAIQwRdp0SkYfsw+ytud5A2h6P 2mO4X9FgNZPuPonPRoDYGTMkD7iUb2xhIolbjYT02XBwEqfkzSuZJ/wd9EI2hBcmQ0Qe ezvFa+tXbHJkQF8VCK9rRqxGtlQ25w+/H9GWwc+Sk1Z2gkh4eIq7ZQtM9UDY/jEI4fNa yvXDxSOScaFWQ5lmrqrAVr5Lobay9FJmoquc0WFYmtmQuXctE3M/mX4JkjjHCRtc8eKf Nllw== X-Gm-Message-State: AOJu0YxOnTrGXBYozFg09ajOfP7Ixqb9EDBc/eiJPnmu+zRbKQVj+W5t pMFABaNtx8yhztrYH3ArT7dVgvkvw3Md+GVp3+QwqTkcDnW7ZHEVL8uiFOwjzYKeTt8gkBdKJi/ B X-Google-Smtp-Source: AGHT+IEYC7/UkVfK/EniMC8KGBcpC359iYeYfd6xmy0RCZV7M1zExuxeEQMrsX1f3BMFqvn9IMqWOg== X-Received: by 2002:a17:90b:4d86:b0:299:d5fa:3e1c with SMTP id oj6-20020a17090b4d8600b00299d5fa3e1cmr3276694pjb.31.1708459489959; Tue, 20 Feb 2024 12:04:49 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:8177:59a3:f5e3:1b0a:262]) by smtp.gmail.com with ESMTPSA id qn3-20020a17090b3d4300b00298f88c3e48sm42324pjb.11.2024.02.20.12.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 12:04:49 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Noah Goldstein , Alexander Monakov Subject: [PATCH v2 0/3] Improve wcsstr Date: Tue, 20 Feb 2024 17:04:42 -0300 Message-Id: <20240220200445.4000158-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Different than strstr, wcsstr still uses an O(m*n) algorithm that might be considered a security issue (although BZ 23865 was marked security- since there is no actual application impact). The gnulib recently added a wrapper to fix it [1] and it is used as the base de str-two-way.h implementation. This patch adds a similar implementation, and different than strstr, neither the "shift table" optimization nor the self-adapting filtering check is used because it would result in a too-large shift table (and it also simplifies the implementation bit). The patchset also added a proper tests for wcsstr, based on strstr one. [1] https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=commit;h=9411c5e467cf60f6295b9fed306029f341a0f24f Changes from v1: * Add more tests from gnulib. * Removed unused macros from wcsstr. Adhemerval Zanella (3): string: Remove c_strstr from test-strstr wcsmbs: Add test-wcsstr wcsmbs: Ensure wcstr worst-case linear execution time (BZ 23865) string/test-strstr.c | 305 ++++++++++++++++++++++++++++++++++-------- wcsmbs/Makefile | 1 + wcsmbs/test-wcsstr.c | 20 +++ wcsmbs/wcs-two-way.h | 312 +++++++++++++++++++++++++++++++++++++++++++ wcsmbs/wcsstr.c | 95 ++++--------- 5 files changed, 609 insertions(+), 124 deletions(-) create mode 100644 wcsmbs/test-wcsstr.c create mode 100644 wcsmbs/wcs-two-way.h