From patchwork Wed Oct 7 17:50:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 40678 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 DC95E3857833; Wed, 7 Oct 2020 17:51:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC95E3857833 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602093076; bh=+zR0Tw0bigyAvsMcnAwBHvQGU5uqXw8E/Z/OGaMiCmk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kL61x5xsctf/rnYP7iS+FHHqEUP/q7kku3FPUvDuq1orwaIxN0sOc5k6DgHGcoqNX bTXAziZhgb9a7f0rO11kXVkmM1ymzs2VJFf0BIdS5B1m4OzY5a25XmqaFsuaBq1iXr V5IJTXZNedZpekdyq26RiMPCssVReRZ2RvJGokN4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2062.outbound.protection.outlook.com [40.107.20.62]) by sourceware.org (Postfix) with ESMTPS id 59E7A3858D35 for ; Wed, 7 Oct 2020 17:51:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 59E7A3858D35 Received: from DB7PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:10:36::38) by HE1PR0802MB2362.eurprd08.prod.outlook.com (2603:10a6:3:cd::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3433.39; Wed, 7 Oct 2020 17:51:10 +0000 Received: from DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::49) by DB7PR05CA0025.outlook.office365.com (2603:10a6:10:36::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23 via Frontend Transport; Wed, 7 Oct 2020 17:51:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT055.mail.protection.outlook.com (10.152.21.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23 via Frontend Transport; Wed, 7 Oct 2020 17:51:09 +0000 Received: ("Tessian outbound 195a290eb161:v64"); Wed, 07 Oct 2020 17:51:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 9c8b166cdb1a5c10 X-CR-MTA-TID: 64aa7808 Received: from a47f95918c8e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D40A0D94-595D-4031-B040-8719AA5A82EE.1; Wed, 07 Oct 2020 17:50:57 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a47f95918c8e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 07 Oct 2020 17:50:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E0xhpk0xN+KoORP94oKmNBRW8ignsLc130E3nYgjUK+yLQH4MeSlhrX6D4SjY5A7UOS3P6pO5lOvXPvv/paSmhw7mnsXPITMz+eV6Bb7KvPiSbgw+EY/iRSYBqqIhldMrI3cUcdFZkojjjZ2q10z/ygqUhVl1a56xhI7xcLOhbMOc5nVrA2tnMEbiFfbjQs6Ow49EDbxKUx/jXhWST88zFW/RG0FMJ0oORr9iZGsnj+YSo1lGVSniLJ0es2mjCpVgjCXiewclbCfP5CcTjiwlpk91NaOaq/kQb3gmo2ICQ/Y6BP9Snbd851YYO7JprSeKmlWX4YkoQz9fYC1jwHgjg== 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-SenderADCheck; bh=+zR0Tw0bigyAvsMcnAwBHvQGU5uqXw8E/Z/OGaMiCmk=; b=U/IGTPtQq96B3uukZT/w2nD3V0ZoRBFwbWZu4zC1cGxVLbB05wzQ6KVBEd9rPR2Nx0U/RvDlLO7PP4kN6s7tRLWkgRQs/pRI0mftVoN/dFIoS6SwQ6qpG4vM/eR7q9ioHtF7ACByTKVPlkMCCSG5JlcIR+NkCdh/Ov10jJyOFbLkmCJT70wM6746vSAwTLQIBWqfM/q0LZbwA0N0VubYS7Wnuw+TsbJkziptbg/UA2ugZ4+H3Dq7XnTKLg2RXQxk2zV9k3f75k6A0HPL8LckXiQdwBnHIkk3ulA/z317+iU/qUjuhHa1qb8FWVLFJxzy5oBnLLs0KofaIQIJZyLwGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) by PA4PR08MB5982.eurprd08.prod.outlook.com (2603:10a6:102:eb::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23; Wed, 7 Oct 2020 17:50:56 +0000 Received: from PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::784a:eb50:9684:50fe]) by PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::784a:eb50:9684:50fe%7]) with mapi id 15.20.3433.045; Wed, 7 Oct 2020 17:50:56 +0000 To: libc-alpha@sourceware.org Subject: [PATCH] Fix aliasing violation in __vfscanf_internal [BZ #26690] Date: Wed, 7 Oct 2020 18:50:49 +0100 Message-Id: <20201007175049.32564-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P123CA0066.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::30) To PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.54) by LO2P123CA0066.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.23 via Frontend Transport; Wed, 7 Oct 2020 17:50:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f5e3d4ea-2938-4d58-9005-08d86ae992fb X-MS-TrafficTypeDiagnostic: PA4PR08MB5982:|HE1PR0802MB2362: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3044;OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 2+G3cOgStOHuaKqG7uvS7+zGXfsUb56Nqa7j1m+DAzqSnPJfx3hPBtQ9jJzXNhJL1byFnZ2rB87N4R++XzGkfIeVQ0n0AAGloRIxoLLQZb/MjQ8P5r7cmMtNk3Xpd5dbpOq9ZUzC0jL4ErDmYMeEwHAG+8LWBhuJhkRGDBfSDjSHsbOWJyx7OzVB9c0FSBhly5nVOk8fWEtozcRvH/YZLlQQcsWJVgiX7hnt0Pw2ylHw86EpqAkdehdOUfv6zhXAg73ql979390eNHa1cMBHuPNpSNveRonVm0nEl7tEA9Xdl5vn/26p3jjMwA2nL8BpmgdXu5xuhjY5ycBhstzk4EvB096KNKD3M7mSoVPE1NgJkpQUAwqcZKzVmhm0HIik X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PR3PR08MB5564.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(346002)(39860400002)(396003)(136003)(6512007)(8676002)(5660300002)(8936002)(316002)(6666004)(66476007)(66946007)(66556008)(26005)(6486002)(86362001)(1076003)(44832011)(478600001)(6916009)(2616005)(69590400008)(956004)(83380400001)(52116002)(6506007)(186003)(16526019)(36756003)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6tBN2NzXZwaODfYIC6RHu/e6eulCUEQv1Sr4W6LNaH08yXYjXUCXMkrMRDfrBQpYiGN2ptu+2ZnRvCPiLzsrW3118Ha0FJHo3QLBFXM4rvh5/bHNZwfBTXrNxgSwq1C7EfYMzR0RHDWg1NW//PfdUWmlR/ExLpWJ8jOtxVDioR9UWalfwnJpGsbrcKUQIvXllAgh5D9Py7bKparIw6KuFOc58Xy+GqefseunMfrm3KfPlbGnb1I5AqdCyOfka2PH4CYIlXduqYsKwm+fdem9IUjiV2fBPbk3rW/KyJSzWABmsMHl6pEjTNAXTscU08PH6QBPXljTh4CipaQXbf0+JmRXimAuul+ncAmLBepWSAfcfLeLeviUIYwvThvxt2/Ri/LAxHLTW2p1jXzA5kzlx33kpUFSgGR4oXQJw9QlmGMRasTVVr72EAseNmMS/DwpviH56sm+VVBE650Yo/TzhScXnKbdbi7H/opnh0nW57yrDTB6dnuIeBIaHfPkv2jAvpBQZdVplQuHh3tDzOO05UKQcrbhAYKfzGhgbnms89lJWs0WZ92uQ8XD9eyi/NX/jTRBsyUnA7q1CsLOQLwJaqxoEr2P7Sqe0NX5FDIB5rsT3oR2lIWmqYRGWkhmXOoNDJau5EMgzYZQ0KAiUfF8AA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5982 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 2c64cfe9-94d1-47ed-874b-08d86ae98a8c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zxAnRPTRDVw8L3Zr9XUSJlhx670Co09jgONSo8Doj6EVbFdvFW6SI1ZW22HkJoTKoZZ8QMzLMRnVSPqQx43okeJg4czgIGBLbL9b+VyzI1iUMRBhLWbL0ZbemDgBen+tDbETTbRop940mFLtj2r++BGdxPDJHHc3Xm3ULSjrX0tQfRX8AOP3TaUW3PGc7f1M7KDzTdTJnKZU5s+fEjt31UuyOeNZ2CebyfaRuekFLFwb4A9yBShLG6xJ1Sk1+p+o+Ni+Q1RhPVLhuopAfTHrwKIKEnf+X2PLWthgukxHL0O0nFKbQ1t8SssPT+PtVwKKjwDmLzozi+vvOducEFigey/TY27E0wDL5nSrWDiF2KJpAT2G1N9QbPPV/1MUgjHAWLcEqG7W01i3mKp471rihonzuuvzJvUHeqK7VlFjuWPKP8Nvv/EmSq7jagsYIGRS 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:(4636009)(376002)(396003)(346002)(136003)(39860400002)(46966005)(6916009)(82740400003)(47076004)(1076003)(44832011)(70586007)(336012)(956004)(86362001)(6666004)(2616005)(5660300002)(6486002)(70206006)(186003)(81166007)(16526019)(6512007)(316002)(26005)(8676002)(478600001)(83380400001)(36756003)(8936002)(2906002)(69590400008)(356005)(82310400003)(6506007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2020 17:51:09.8744 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f5e3d4ea-2938-4d58-9005-08d86ae992fb 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: DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2362 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@sourceware.org Sender: "Libc-alpha" Internal stdio code uses both CHAR_T and UCHAR_T strings. But the internal helper read_int was only written for UCHAR_T. A CHAR_T object can alias UCHAR_T, but CHAR_T * cannot alias UCHAR_T *. This means a cast like (UCHAR_T **)&pc is likely a bug in the code (currently GCC does not warn about this see PR97321). The fix introduces a read_int_char variant and removes the problematic casts. (The mixed use of CHAR_T and UCHAR_T may be a design mistake in stdio: if everything used char and wchar_t consistently then aliasing violation would be much less likely, but fixing that requires more refactoring.) Fixes bug 26690. --- stdio-common/vfscanf-internal.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c index 95b46dcbeb..d832493623 100644 --- a/stdio-common/vfscanf-internal.c +++ b/stdio-common/vfscanf-internal.c @@ -135,6 +135,16 @@ #include "printf-parse.h" /* Use read_int. */ +/* Same as read_int, but for CHAR_T * instead of UCHAR_T * string. */ +static int +read_int_char (const CHAR_T * *pstr) +{ + const UCHAR_T *ustr = (const UCHAR_T *) *pstr; + int retval = read_int (&ustr); + *pstr = (const CHAR_T *) ustr; + return retval; +} + #define encode_error() do { \ __set_errno (EILSEQ); \ goto errout; \ @@ -486,7 +496,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, /* Check for a positional parameter specification. */ if (ISDIGIT ((UCHAR_T) *f)) { - argpos = read_int ((const UCHAR_T **) &f); + argpos = read_int_char (&f); if (*f == L_('$')) ++f; else @@ -522,7 +532,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, /* Find the maximum field width. */ width = 0; if (ISDIGIT ((UCHAR_T) *f)) - width = read_int ((const UCHAR_T **) &f); + width = read_int_char (&f); got_width: if (width == 0) width = -1;