From patchwork Fri Oct 28 16:40:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 59588 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B85693829BCC for ; Fri, 28 Oct 2022 16:41:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B85693829BCC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666975317; bh=DcEWRz1T2YMiKB1yUYcHF+CnKKG+rgcer1lEyZ+MLMc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ksGptw81S+M+eiAwYmB+pxpycT58ACLBJvED/Dmax0XDmeIlLRb5jY8nxee6x2WcF FFw5DashdC3lTwMFj0vJTUcgNKJcbQKKpzevDQmi0hZxk2p+eVzOUuBvhQtkiHIV/1 8fiIq9h2bC3QneTrTJeXrYfj/tHVH9EAlI2WSo7w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80047.outbound.protection.outlook.com [40.107.8.47]) by sourceware.org (Postfix) with ESMTPS id 3ABEE382DE0E for ; Fri, 28 Oct 2022 16:40:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3ABEE382DE0E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=deYQlEc9KrjFC80sv8YNgtY6pW3tENryYLtp+YsBhln9jXIwxrzDq2IuidALJ77XgV3/raBeAQb0um9++CzcJRWaLZSD6JoQ+uV6OH8h/QLohcWLNxE9+JfQqzwp/s5A7Fe9Tg+5bbmf6/xprI3XNPYGmz1VkCWSb+qcD2cqn98Dab2EvKIamJaBAoZm/5ZC0oGJjPUq8/T4mp+C5JVzwva4YkySzQQ3CSkE8vlaObsHnNoOvrHJGs9kczcGrpVArQ3TXMUBDGE/tsKhssThJiaxi+UgdzCY9ZG5N2zhnz+eUVpWQdealNZBWlLaVVv5Lk1atHtHRIc29J3cLd44Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=DcEWRz1T2YMiKB1yUYcHF+CnKKG+rgcer1lEyZ+MLMc=; b=mmsS72DpdCD4Bn5mfhCFGpyZmH62Du7Cw0TtzwdpZLr445zRT16qTXkpr374XutQnGWCNbqARDQSjpbN5j5tsOF2e1rOvX3WtlvdytMyg4aT1CbET2SAB86rEl89Sx9AzG3J4M+FJGcmCOkncQeJ5PHrkPvPjWzTYR1KNRLED/sM2LxELdPaEqteDB+5eDZchALnEsjjgbhXn/aTFPRWf5DTTyEno7rFBwUxoWhD8MhoOzrSf1G1p6ERZRtuZcmezp9W+DqRdggqCA3ufKZcI6lwGJLOdckOTZ5f+DQAa6+2d3kiLFZZ5dPBDD5ou86T18WR+V/XkuRLBO/F3WU47g== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from DB6P18901CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:4:16::23) by DU0PR08MB7811.eurprd08.prod.outlook.com (2603:10a6:10:3b5::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14; Fri, 28 Oct 2022 16:40:16 +0000 Received: from DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:16:cafe::76) by DB6P18901CA0013.outlook.office365.com (2603:10a6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.15 via Frontend Transport; Fri, 28 Oct 2022 16:40:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT034.mail.protection.outlook.com (100.127.142.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.14 via Frontend Transport; Fri, 28 Oct 2022 16:40:16 +0000 Received: ("Tessian outbound b4aebcc5bc64:v130"); Fri, 28 Oct 2022 16:40:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 92b4d2fa1162d165 X-CR-MTA-TID: 64aa7808 Received: from 7a16a1a58abb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BA3E157A-7055-42B7-940F-1425A62B88F6.1; Fri, 28 Oct 2022 16:40:09 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7a16a1a58abb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 28 Oct 2022 16:40:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tt//pN9/6ASPMfT6ExcLS/O8AqfqmsOVWjFezmTf7EKlEHAJPh4bSCcaQ0v8pLRfMOa5VFmFTiGHNNSheJ1hxojnyzexb64mLYwlavBtpKKUU/+nUDJobJekViWBIQvEKiu/OkQa9BsNxxrD/fRZ1K8aMf1fCvhWMYIz4bvK28d3/En3mwJSbbYGYLlomrgs/SxUcwVTrh8vLC4qPDU+QS4+CpDjHZO20R+wCBMGgbFbY5hlkod9NwFHZv/Acatz1KYzfdvOtdEKdGEV8Bp5gTAc+VaPPU1JlX9J6Rbz4YVtMr8uRj36g9gxMQ7z2HQ1w4W+vOXBR08cpUrYAADzvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=DcEWRz1T2YMiKB1yUYcHF+CnKKG+rgcer1lEyZ+MLMc=; b=nM9R7a1kcWVZMMTqpGHwkKEVPZdL2F4ZQUJ9ObA4VbZdT3OlpC/OgVksJw2W4Tx+cHdzUeBYZllCZQY3XxCmJHLxkaCPjga2qHaG+yRITUkkEFv6j6EWmfUeGTWjnqY2Rbo2/GKh6BaVCJ6WqtnD9wsSQ9CGIYLTqkQfwL/izU7BNwiWh2mQv39GEHaObxuLK+qfzknIE3TXVg1WxeyR7Q3cPCzq9VTmEfumZjst6TSSb3UpwjI59m0rRRDPt3S4wM7yyRqA4MCVcqhJSgJrirGXzujbOGQEV/CxIRF6i7z4qjAo3Rt9gWXS7aG9S0UyWEqImAH2gjsnJ7gsYnJZuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AS9PR07CA0039.eurprd07.prod.outlook.com (2603:10a6:20b:46b::11) by DB4PR08MB8149.eurprd08.prod.outlook.com (2603:10a6:10:383::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.28; Fri, 28 Oct 2022 16:40:06 +0000 Received: from AM7EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:46b:cafe::29) by AS9PR07CA0039.outlook.office365.com (2603:10a6:20b:46b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5769.15 via Frontend Transport; Fri, 28 Oct 2022 16:40:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT053.mail.protection.outlook.com (100.127.140.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5746.16 via Frontend Transport; Fri, 28 Oct 2022 16:40:06 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Fri, 28 Oct 2022 16:40:03 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Fri, 28 Oct 2022 16:40:03 +0000 To: Subject: [PATCH v2 2/4] Fix off-by-one OOB write in iconv/tst-iconv-mt Date: Fri, 28 Oct 2022 17:40:03 +0100 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT053:EE_|DB4PR08MB8149:EE_|DBAEUR03FT034:EE_|DU0PR08MB7811:EE_ X-MS-Office365-Filtering-Correlation-Id: 01ea0b0c-e0ab-4e40-c18c-08dab9031802 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: PdI2PaR0kue6WzZlkSsWanoic1nvopbSKB1x35OFX3lFDFDIzUvH3IW9K+LsPusc2aKRbQVYZFxPMi3ndb02WYMKymaZRgBTg76/GJnpKYkcE9o2LtRrstcB/VmABHDPiVGOhzpu6wxJ0pG2aAtoGEySgarwP/BIlxOlwIQvYT5G1yBigVv2okms8yZ0mfW7m0PQ+e0ySQQ6rTSuSnlGmN2Pb7AZ79olz2+IGT0Xt2Y4zscMcTvg8vMgcshvnAEEHUrTBpFqSqCw3gWm8mMgSWsLCNFIT4O7DUzLZKtV1L5qkGUkJRKkJ/iwVQHTi8Jzd6mAbB4Yr6WgsPV02Tnj8ewr38pbOmP7qY+PlaUi3vcgL3VC0i+BoiPrNUOBXnoWWysu2TXL6nD1zi3XZrtAB6nYFgcGVJDDld47pG/s4E4p7CkMxYnZFM8YH1FFbxtcAUvuexOMGy5pV7V0sJX9qGqyS1X5WbKdNBaGIVnG6bG0mQNyjw0CqMW2nbur19EndZbYJ4/KaL4evxaTuZI27O+gRuHmsSpkaVp4qVqllbIDkmSaHi/5EeaeVnWPZfGnKvXvGE+fx6NX2nYK6iUnbPl6uilIaEBIpM9glwL2iO0XelkTBCf6FNLdhLFsqxrQMpJHpzhg8Jo0sonSPnKvU2YYgCzwjVIcuOO9kfZQ4ySAENLunWMt86uPQgo6qcVKVX5ZHOXC6qhOUAgnZAOmyNMeSG5KyrWfEMk9qCGfgo74vfyvMqKinEQsZAnSAE7lQBIPtbiVEvg+3nvclwXi+VkMOBAsn/j00akP2YSrziFcX8UuIDKrJtQq78nu9iFA X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230022)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199015)(46966006)(40470700004)(36840700001)(70586007)(44832011)(2616005)(40460700003)(41300700001)(5660300002)(2906002)(186003)(336012)(36860700001)(478600001)(8936002)(70206006)(316002)(356005)(6916009)(82310400005)(426003)(47076005)(86362001)(8676002)(83380400001)(26005)(40480700001)(7696005)(82740400003)(36756003)(81166007)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB8149 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: cb8f483b-7092-43e5-14d2-08dab9031234 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6vOoYCN87aVen3oCZsxOtTdw+h83OC5QnNAwG1UtC0spA342w1Ri+oSeFmzgOHyNQYTgJ38IvrJXQqbrCJu6FBHzA18hb0MbAxhuwfxMAUx6x/Wz01EUdDFm08nazXrinVhXjCme7UR3LDGUFS5fQQQoFjChKV4RI5zrgDAVvLJzCNX5cACvSIXlvOchHJ5rOgsfC3OqSqVESM7gQYY9uML7JISkTs/ne4c6qlBJgNl/lB/fhDm/fZrlqDBZmYrz7UNqgnKfGNNJQeyl1UzjBNddYxRg1ibUblz6ZTtBkm3wEGECNGHl850PheTCsIniScSU0i7tNIrudQHhr47djyzhQZsq5mmKC/ndH3csHBnV0/d7D390RPdB1iVUKFvA/6JUqkiQCLIwoyyou0DF6yWWr/AQQ2+/yt7KWbXO6/PglIigQuAQw/ibnpVl55S1bjgwRfMadtwJwP1HJR4Ycns6DE+pQc7PYq7S49URm+QQh9O+VpYvHvLpiDFIeRGcd8ij+ghHMMhhRRkfxjEm3zjHCKT5V0gYQOhuEsmpWvNf+8HpKOYr+vEQ/jEl3ngObVo9Tp07GKErO2x56uy8sgz5QDk6VBP3uYe9tigAlii0SQ9IB8ySheRXrnmvVtnk0IJ9TYeGy8VRXOV1Z3VEz2beUBgemwIGmfzNGMFVeHZldElW5RzySf01ON7z1Rghcz/2lSBVDP/z4wXAEWeKB1RKZKB+iRmvkHAAQ3ASWUzy9cBqPJ9hNmNCBKc51RgIK1dRJpdb72/x3TQwPHoa/g== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199015)(36840700001)(46966006)(40470700004)(40480700001)(478600001)(316002)(6916009)(86362001)(40460700003)(70206006)(8676002)(7696005)(70586007)(41300700001)(336012)(26005)(2906002)(186003)(36860700001)(82310400005)(81166007)(36756003)(44832011)(47076005)(426003)(8936002)(2616005)(83380400001)(5660300002)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 16:40:16.5220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 01ea0b0c-e0ab-4e40-c18c-08dab9031802 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT034.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7811 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The iconv buffer sizes must not include the \0 string terminator. And the output termination with *outbufpos = '\0' was OOB. Consistently use non-null-terminated buffer sizes. --- v2: dropped \0 and replaced strncmp with TEST_COMPARE_BLOB. --- iconv/tst-iconv-mt.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/iconv/tst-iconv-mt.c b/iconv/tst-iconv-mt.c index daaebd273b..36afd8aed4 100644 --- a/iconv/tst-iconv-mt.c +++ b/iconv/tst-iconv-mt.c @@ -57,12 +57,13 @@ worker (void * arg) iconv_t cd; char ascii[] = CONV_INPUT; + size_t bytes = sizeof (CONV_INPUT) - 1; char *inbufpos = ascii; - size_t inbytesleft = sizeof (CONV_INPUT); + size_t inbytesleft = bytes; - char *utf8 = xcalloc (sizeof (CONV_INPUT), 1); + char *utf8 = xcalloc (bytes, 1); char *outbufpos = utf8; - size_t outbytesleft = sizeof (CONV_INPUT); + size_t outbytesleft = bytes; if (tidx < TCOUNT/2) /* The first half of the worker thread pool synchronize together here, @@ -91,8 +92,6 @@ worker (void * arg) &outbytesleft) != (size_t) -1); - *outbufpos = '\0'; - xpthread_barrier_wait (&sync); TEST_VERIFY_EXIT (iconv_close (cd) == 0); @@ -104,11 +103,7 @@ worker (void * arg) if (tidx < TCOUNT/2) xpthread_barrier_wait (&sync); - if (strncmp (utf8, CONV_INPUT, sizeof CONV_INPUT)) - { - printf ("FAIL: thread %lx: invalid conversion output from iconv\n", tidx); - pthread_exit ((void *) (long int) 1); - } + TEST_COMPARE_BLOB (utf8, bytes, CONV_INPUT, bytes); pthread_exit (NULL); }