From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119525 invoked by alias); 21 Sep 2018 11:18:23 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 119513 invoked by uid 89); 21 Sep 2018 11:18:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.1 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=impl X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr20076.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.76) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Sep 2018 11:18:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eu6cao0JSFQ52fvuzePTBsWLPsI39XIrufluABAle9c=; b=o0dnY2zpQf2Ko6cGHXgsmUAxfwrZA3rrcq5v1p5EhYO3Uvcjsqtz5cgxFkVZ9CPoCiZK0Bi8rsoMjCPMLLKROoKeLAwqtPVHaPwQx5vK+XVpEQg6IWJkS2/2QGfchiziaLyyKjgqxNnDc33v4uRT+hdetlqNjXGou9oDgx0bDDg= Received: from DB5PR08MB1030.eurprd08.prod.outlook.com (10.166.14.15) by DB5PR08MB1061.eurprd08.prod.outlook.com (10.166.14.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 11:18:16 +0000 Received: from DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::9867:9057:ef1a:8d8e]) by DB5PR08MB1030.eurprd08.prod.outlook.com ([fe80::9867:9057:ef1a:8d8e%4]) with mapi id 15.20.1143.019; Fri, 21 Sep 2018 11:18:16 +0000 From: Wilco Dijkstra To: "libc-stable@sourceware.org" CC: nd Subject: [2.28 COMMITTED] Fix strstr bug with huge needles (bug 23637) Thread-Topic: [2.28 COMMITTED] Fix strstr bug with huge needles (bug 23637) Thread-Index: AQHUUZxHsMUQPVHuqUG+pNtP9kk3SQ== Date: Mon, 01 Jan 2018 00:00:00 -0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-originating-ip: [217.140.106.52] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB5PR08MB1061;6:LZoBD7YSM9VEVEwCinclHs/BdIfnZmTHrPrSeM/mqeTOZLtaraPWXaGReD31enV7wcuwIulr0nauHTZtM6s2mkO7ITuG3cFepll9ZTPCSc4O1jM4+gOmPnP0XSQ1LQyKVH1BpldhWp5wFELKAna1tQRbU9iy+1PdRskk8mokoHHSe35JmF+0Z0z3XJ6hTVXvloXrnmcNof3qh+Tp+5Eady1MilJKVsorTDOqHQCjfWbiK/lkatbXfpLQ1Ak/Kq9/Z4Go+UQFovIFDCx358GQxB+QQfB6jI9yeurBXWCYawdXi0FL9srXnY27xaTsgKD6ISEekb+78El9YdEu2KZ4sLaj8QbQiMJiJQ+bTg9Ba2YETcxa8I2m+jY35kAU0Uz/cowAaifSHCuROJOz6X/fHaxgYHG1s/avEUQKCiL240irs5xbMlwe6cR6lwiYYVr6IIwK/3/0gKL8LhIQpc0PCA==;5:LSlbmuEULmP3YqKnqj6NL0Ra6VgOITf8uM4Rfk6FMdycF1tMW7zdQPEfpwFguk1ZC9UiWuQgsovgzZkHvK6XnQ/lp21qzlznyaoeDmpuJE0goSjWUzo89AUjPZZrr1iOiBN/GSrmygQFdxaRufNvPCkCCQuTOM9xSwhpLTJ1DzU=;7:uGRP8LCixCwukrQkCaJPOIYvYGzSv+81cCG4/B2hEu9i4DeBqunaHXwn6cgE0pCALYZibq5mU5edvclo4ruwmdZ3RC2vHD+9ZaD2uiA0cS6tU5BT5FisPDJn2Wby5aras5jx02+5QYQWWuZHDrPf8YhxiRR0qpjsKLtdZONs8Cy4FZou+q8VZUqPa6m/jrMRf1QowmdiUm4BLdv1a8d38zfxKseQ86gWZQCgcWCd/LvvNdFAjvYXKglmS0xr0Nzn x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: b31556b5-734a-4438-8df5-08d61fb3ed62 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB5PR08MB1061; x-ms-traffictypediagnostic: DB5PR08MB1061: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051);SRVR:DB5PR08MB1061;BCL:0;PCL:0;RULEID:;SRVR:DB5PR08MB1061; x-forefront-prvs: 0802ADD973 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(376002)(136003)(346002)(39860400002)(54534003)(189003)(199004)(14454004)(2900100001)(6506007)(256004)(33656002)(102836004)(305945005)(2906002)(81156014)(81166006)(8936002)(74316002)(66066001)(3846002)(6916009)(8676002)(26005)(68736007)(7736002)(55016002)(316002)(105586002)(476003)(486006)(9686003)(6116002)(53936002)(5250100002)(6436002)(7696005)(575784001)(5660300001)(25786009)(4326008)(72206003)(5640700003)(106356001)(86362001)(2501003)(97736004)(2351001)(99286004)(71190400001)(478600001)(71200400001)(40753002)(14583001);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR08MB1061;H:DB5PR08MB1030.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: XLGxYMWBQ2wP2CU1kUKGaqWSCWAUVB14wAyPV+1gu92yuGsaPInjEPzhdYXYO3ty64FR9VwHOUgfsJmtSdhmamKiKLMq1yrYgXLSWPdJow93OqCfQxKHMeLqUi8pKpMOeS7v5fbSqgwcANz81Y3TCepsezinHW8wwWztyVmyc6tf51CkSXtojrFp1KKk2jxcAM9tmlhXpmhwY3rfn5C/wWO4Z9+EnXLkmnxGuJgoplq6WRuv+XCNM3ealLI03ysv9Lvyt49fKivO9ZzBiQBanrCXxhDjZO5E+I3tURIWn0ihVB6EZbhNuipRUJ2XxiFqkhhxXLso+GSBWJrS7h110j0HZcE+y02GZW83Wz4RIqE= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: b31556b5-734a-4438-8df5-08d61fb3ed62 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Sep 2018 11:18:16.0988 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR08MB1061 X-SW-Source: 2018-09/txt/msg00007.txt.bz2 Fix strstr bug with huge needles (bug 23637) =20=20=20=20 The generic strstr in GLIBC 2.28 fails to match huge needles. The opti= mized AVAILABLE macro reads ahead a large fixed amount to reduce the overhead= of repeatedly checking for the end of the string. However if the needle l= ength is larger than this, two_way_long_needle may confuse this as meaning th= e end of the string and return NULL. This is fixed by adding the needle leng= th to the amount to read ahead. =20=20=20=20 [BZ #23637] * string/test-strstr.c (pr23637): New function. (test_main): Add tests with longer needles. * string/strcasestr.c (AVAILABLE): Fix readahead distance. * string/strstr.c (AVAILABLE): Likewise. =20=20=20=20 (cherry picked from commit 83a552b0bb9fc2a5e80a0ab3723c0a80ce1db9f2) diff --git a/ChangeLog b/ChangeLog index bda9634..a111f01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2018-09-19 Wilco Dijkstra + + [BZ #23637] + * string/test-strstr.c (pr23637): New function. + (test_main): Add tests with longer needles. + * string/strcasestr.c (AVAILABLE): Fix readahead distance. + * string/strstr.c (AVAILABLE): Likewise. + 2018-09-19 Carlos O'Donell =20 * stdlib/tst-setcontext9.c (f1): Rename to... diff --git a/string/strcasestr.c b/string/strcasestr.c index 5909fe3..421764b 100644 --- a/string/strcasestr.c +++ b/string/strcasestr.c @@ -37,8 +37,9 @@ /* Two-Way algorithm. */ #define RETURN_TYPE char * #define AVAILABLE(h, h_l, j, n_l) \ - (((j) + (n_l) <=3D (h_l)) || ((h_l) +=3D __strnlen ((void*)((h) + (h_l))= , 512), \ - (j) + (n_l) <=3D (h_l))) + (((j) + (n_l) <=3D (h_l)) \ + || ((h_l) +=3D __strnlen ((void*)((h) + (h_l)), (n_l) + 512), \ + (j) + (n_l) <=3D (h_l))) #define CHECK_EOL (1) #define RET0_IF_0(a) if (!a) goto ret0 #define CANON_ELEMENT(c) TOLOWER (c) diff --git a/string/strstr.c b/string/strstr.c index 265e9f3..79ebcc7 100644 --- a/string/strstr.c +++ b/string/strstr.c @@ -33,8 +33,9 @@ =20 #define RETURN_TYPE char * #define AVAILABLE(h, h_l, j, n_l) \ - (((j) + (n_l) <=3D (h_l)) || ((h_l) +=3D __strnlen ((void*)((h) + (h_l))= , 512), \ - (j) + (n_l) <=3D (h_l))) + (((j) + (n_l) <=3D (h_l)) \ + || ((h_l) +=3D __strnlen ((void*)((h) + (h_l)), (n_l) + 512), \ + (j) + (n_l) <=3D (h_l))) #define CHECK_EOL (1) #define RET0_IF_0(a) if (!a) goto ret0 #define FASTSEARCH(S,C,N) (void*) strchr ((void*)(S), (C)) diff --git a/string/test-strstr.c b/string/test-strstr.c index 8d99716..5861b01 100644 --- a/string/test-strstr.c +++ b/string/test-strstr.c @@ -151,6 +151,32 @@ check2 (void) } } =20 +#define N 1024 + +static void +pr23637 (void) +{ + char *h =3D (char*) buf1; + char *n =3D (char*) buf2; + + for (int i =3D 0; i < N; i++) + { + n[i] =3D 'x'; + h[i] =3D ' '; + h[i + N] =3D 'x'; + } + + n[N] =3D '\0'; + h[N * 2] =3D '\0'; + + /* Ensure we don't match at the first 'x'. */ + h[0] =3D 'x'; + + char *exp_result =3D stupid_strstr (h, n); + FOR_EACH_IMPL (impl, 0) + check_result (impl, h, n, exp_result); +} + static int test_main (void) { @@ -158,6 +184,7 @@ test_main (void) =20 check1 (); check2 (); + pr23637 (); =20 printf ("%23s", ""); FOR_EACH_IMPL (impl, 0) @@ -202,6 +229,9 @@ test_main (void) do_test (15, 9, hlen, klen, 1); do_test (15, 15, hlen, klen, 0); do_test (15, 15, hlen, klen, 1); + + do_test (15, 15, hlen + klen * 4, klen * 4, 0); + do_test (15, 15, hlen + klen * 4, klen * 4, 1); } =20 do_test (0, 0, page_size - 1, 16, 0);