From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by sourceware.org (Postfix) with ESMTPS id 8A31E387086A for ; Thu, 21 Jan 2021 13:53:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8A31E387086A Received: from DB6PR0501CA0032.eurprd05.prod.outlook.com (2603:10a6:4:67::18) by DB7PR08MB3354.eurprd08.prod.outlook.com (2603:10a6:5:1d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 21 Jan 2021 13:53:26 +0000 Received: from DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:67:cafe::4f) by DB6PR0501CA0032.outlook.office365.com (2603:10a6:4:67::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.14 via Frontend Transport; Thu, 21 Jan 2021 13:53:26 +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 DB5EUR03FT064.mail.protection.outlook.com (10.152.21.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Thu, 21 Jan 2021 13:53:26 +0000 Received: ("Tessian outbound 28c96a6c9d2e:v71"); Thu, 21 Jan 2021 13:53:26 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3479cd71ec551891 X-CR-MTA-TID: 64aa7808 Received: from 53332dc73fba.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 14764CCE-47B6-4BE9-B8D5-F51A088838CE.1; Thu, 21 Jan 2021 13:53:04 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 53332dc73fba.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 21 Jan 2021 13:53:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wrq3KGd+vLpO9f5OA+Yo6QiZDsmp4Q0YOJQ26f48MHMYo3eCcqOcCFchr0NfwPZc+ykqlUq1rapxNu0uOiV1hjSsQ/Qpj5/JK0UXLcQa2clNKEZrBbU/UnS5V/3pUB0AXfRgZnSvw7HMNbP6ygS/cB0jAXM+9sA9Y3yndy+dlAP455jz1LPfnkUukBQG4usRj/f52YKR8q+cmxDKogjgXgioJOKzuioEEma8YULzqaE/zfkEJ54pUM1S+bVQljMn27O2EVgNzCa5zpgn1+eZJY5tZYi4iM4DrtyJWwkpZbnOHt0Z1Z3NUwjZUmRMRkCXPuwK10J+gCsUjBrtqpK7Dw== 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=/ly+y0j+YQ2GnSxf6odIMF0agO6LTOCOxBkAy8jb6K8=; b=E6ij/d6tUiQolLyTOzaqq4/A9889+EW841dal+i0cFMko7dWyQZi5UF0pD5Vm8hTO8VmXCj3tbKIAmDobHk+2DFcainXugF1z42Wgf74jU3ZVLbvY9ZpURRlXMC9pbhWcZUvmXR+3mvBY2fOhPrmUNv9k8OKBuh68f2hxzzcEL75iVIyEEmQ4VG2ZoqNNbzGdHe5ia8m/0DWqkfXXgrkzqqI7OQq2MXeM3kh7AqWkCFehTgwcKgoLlSXjeXipNIRVEtPmGapIRonbvVUcGUFYVymSRfQWobtsAoXppE2z3IH6MAKHlRsnb8Jw7T+CAbGsJs8I6QzFMVIn94BOzGvQg== 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 PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PAXPR08MB6398.eurprd08.prod.outlook.com (2603:10a6:102:12d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Thu, 21 Jan 2021 13:53:02 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::700f:ddbe:a347:ee4f%7]) with mapi id 15.20.3763.014; Thu, 21 Jan 2021 13:53:02 +0000 From: Szabolcs Nagy To: libc-stable@sourceware.org Cc: Andreas Schwab Subject: [2.32 COMMITTED] __vfscanf_internal: fix aliasing violation (bug 26690) Date: Thu, 21 Jan 2021 13:52:50 +0000 Message-Id: <20210121135250.20572-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: SN4PR0201CA0066.namprd02.prod.outlook.com (2603:10b6:803:20::28) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.55) by SN4PR0201CA0066.namprd02.prod.outlook.com (2603:10b6:803:20::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Thu, 21 Jan 2021 13:53:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 15c1b676-8347-48ea-e3ee-08d8be13ed49 X-MS-TrafficTypeDiagnostic: PAXPR08MB6398:|DB7PR08MB3354: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:220;OLM:220; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: bYGd/gIYqOfKnAt9ef/uR8KjjeUn7FX9DmpPngP16rwp2VKy71TOyF3AxovJHVNkcpTTxsMPxyZIBTx9R+Ygg7z19XKqrhkZ27fs8DiR5iXRQuuEAXFrxTXA4oGygVEt8FSnbBFMfdy2IA0x1mtPNOAeRz8IKINRoMhkf6CN2c9dKMHE+rv2I+HZa74JifW8KXTXKqZOnyyBoYLnvahzPPlkTR8E/t+BptbkWumJynFfPzYmGKxZiMaIVyGP6/dwYDgFKsHk9rNbtS3gnvN6viBNIcXlxFKJQcOJ1RrU5rl2oN6HPE0VbEEnxdENSWc+pU2gKWgsAOlgyYVWjrBSn+em+OXeRG5xq16iCSnEZcnmpuFjU6yYgwZdqnbAA5vEYjDyY/NTW0ybkK2TokjELJkQHEJq6w01olwkfHMeKDz8TKLGe4yUV5K/2uGlKYtTw023tf7JzxhGbYAqtZ8Ji3EPD3JmVChrMJ77uMghuowW8R/3Xok8IcuG0XS46x2i5LlsAYZesKuHw0EApEaGJw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(366004)(396003)(346002)(39860400002)(1076003)(44832011)(2906002)(6486002)(69590400011)(6916009)(316002)(52116002)(478600001)(8676002)(4326008)(5660300002)(186003)(66946007)(956004)(6512007)(26005)(86362001)(8936002)(6666004)(66476007)(6506007)(83380400001)(36756003)(2616005)(66556008)(16526019); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?vG1lF56A8dj5w0Clxh4o9V2ciHeV6zUVuUH0FZCki2CrMS7PBT9+5qdC8fxz?= =?us-ascii?Q?J8uaKrcKkQOu4yoxxcvCCmsL1M3uO6RhGmftZog0y8HAeUjRszbmgWeMGPnN?= =?us-ascii?Q?oRnJk96e9U2XKINkXD47PFF9/DAtMxUArAUdLXEqvtXpDqynGHquxxiHaFs0?= =?us-ascii?Q?x2xNFB/6zGF2XeGPS/XmNQbM4JTl64hI29gVsQk6rcKZAjwp4CpBRzt4PAgQ?= =?us-ascii?Q?ccGBZapMGlsIzQkNOV5BP8mD0LpYbdieMsOz8CULaver/ObTUsNw22zumd7S?= =?us-ascii?Q?FcnogG3xI1Cgbx/TX+XhTPBizgNioYb/j4zja3gae309ygw5yLAbR1y8c9aX?= =?us-ascii?Q?Jg0VW9zF4jyKBFkSntxGnoYRWR0BXNck9WqObFOKHfDCOtdg84DDfaUcTWJg?= =?us-ascii?Q?1YQ0EUCoBsu9Dl+t8NE8n4gZVRRPJvd5D1z9NUf9d0FU9JwV9XYmFU2oIFOe?= =?us-ascii?Q?W5GkYKasMVQhR5KyaKiji45LpFimaVWMgSIkGmObQv8dZ25upeuT1Qq+9Zc7?= =?us-ascii?Q?BbA7otwuvjcGfxcBgy28DCTArGZP7BzmFD8Z52U+giRylPDmFOLFST9ZseCW?= =?us-ascii?Q?mao/5ElY5orEsf9ouGkVKLtUuQizJVcaGg9Y0WcX7GohlBJ39gpaw97t0TYF?= =?us-ascii?Q?kfNpqIR015Tr4Q/hM5k44nFYFgrJgP5Jh0iYTI6GePoNzNGX1j/I/wyRtgfn?= =?us-ascii?Q?LGTvxBZJOrx43Mk45p63M5F5U6OSyp/loi4GM6ddu0FvDy+U7eynEoKCAcQ3?= =?us-ascii?Q?NQuQvtrEJaJNKVL4Cjoi28OOs8JtoAwCma/UaG3Yx4Jvj3JyqetSjIiTzMUW?= =?us-ascii?Q?UTP+j7GNcgDQhod+anrXlxyVU0O+rTtUC/lwcxvrml5/Eiz9mdq+o6crdNHX?= =?us-ascii?Q?2awJ2tIhSta4W9EZYo1/ma+VcKear08PE93kRx13eTkzscGRj669YRutS5Xl?= =?us-ascii?Q?zfJqrPyM0exl5hwgwyZ4t4viOU2DViW8V+1+kwuCQa2d4s63IRb6M8+NhUaM?= =?us-ascii?Q?Ld+T?= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6398 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: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: dafede4b-1bac-4200-ad2e-08d8be13dea4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gKXAT/1Ve45hdq/az3Q3zYQW0lt2DSn/DtTjdKlM2/hd29f4ofve6XbgxWlTbQ2XPo9tvqwW9j9XUa7QZ4KSzjwqJaa5F6ahUDckorYxj9F4TH781cmhrEWuMYyMHIPeJwLVTUQwEZkqgmh8ph+vVvMaeon5qGN95MyGRjG2yxbE6Fmzj2F4jT3Uu+nkxJbPnmVT0gSeIrT3lcGVC7Yvtw18av6gz3akfpHoaesTp0Mwe51SayNJHBKxMiwSf1uJRHsw8kDz5roMJxF+h+IZEz9oE53sET37mK9iCmsfr/NtemVH2qfcdWSiKLnEQxOq8Fh33Sd64snBWLUjRhNMl3d83x59RdiHQi5vwHR5+LiDzntx67TCfPEFClA0LJWds4++jEFSWFrYPF/LyuCGP0EZzbcFe9u1XwbuLWdIqX3Jwx4nMq6UR9QqlnSQ2H6ji8RP0V4t7G8RXy3iFWabnrguyJU5tm1gD18I8v/IJf0RcD0jJma5o9JBr9poU5yyJ6HzFL640U9XEOwqO45VfsZtdzfk0U/MBa13xyeUTXDDpNrNhgND9JTwmTVGKtRXNUwavTMqebcj6xqW6NaeQQ== 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)(39860400002)(376002)(346002)(136003)(396003)(46966006)(44832011)(70206006)(956004)(356005)(4326008)(8936002)(8676002)(1076003)(107886003)(478600001)(86362001)(336012)(70586007)(47076005)(316002)(6486002)(26005)(16526019)(82310400003)(2616005)(81166007)(6506007)(2906002)(83380400001)(5660300002)(69590400011)(6512007)(6666004)(36756003)(6916009)(186003)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2021 13:53:26.7549 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15c1b676-8347-48ea-e3ee-08d8be13ed49 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: DB5EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3354 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, 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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2021 13:53:30 -0000 From: Andreas Schwab As noted in , the cast in the call to the read_int function is an aliasing violation. Change the type of local variable f to a pointer to unsigned, which allows to eliminate most casts while only adding three new ones. (cherry picked from commit c0e9ddf59e73e21afe15fca4e94cf7b4b7359bf2) --- stdio-common/vfscanf-internal.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c index 95b46dcbeb..3a323547f9 100644 --- a/stdio-common/vfscanf-internal.c +++ b/stdio-common/vfscanf-internal.c @@ -277,7 +277,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, #endif { va_list arg; - const CHAR_T *f = format; + const UCHAR_T *f = (const UCHAR_T *) format; UCHAR_T fc; /* Current character of the format. */ WINT_T done = 0; /* Assignments done. */ size_t read_in = 0; /* Chars read in. */ @@ -415,10 +415,11 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, #endif #ifndef COMPILE_WSCANF - if (!isascii ((unsigned char) *f)) + if (!isascii (*f)) { /* Non-ASCII, may be a multibyte. */ - int len = __mbrlen (f, strlen (f), &state); + int len = __mbrlen ((const char *) f, strlen ((const char *) f), + &state); if (len > 0) { do @@ -426,7 +427,7 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, c = inchar (); if (__glibc_unlikely (c == EOF)) input_error (); - else if (c != (unsigned char) *f++) + else if (c != *f++) { ungetc_not_eof (c, s); conv_error (); @@ -484,9 +485,9 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, char_buffer_rewind (&charbuf); /* Check for a positional parameter specification. */ - if (ISDIGIT ((UCHAR_T) *f)) + if (ISDIGIT (*f)) { - argpos = read_int ((const UCHAR_T **) &f); + argpos = read_int (&f); if (*f == L_('$')) ++f; else @@ -521,8 +522,8 @@ __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); + if (ISDIGIT (*f)) + width = read_int (&f); got_width: if (width == 0) width = -1; @@ -2522,12 +2523,11 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr, } while ((fc = *f++) != '\0' && fc != ']') - if (fc == '-' && *f != '\0' && *f != ']' - && (unsigned char) f[-2] <= (unsigned char) *f) + if (fc == '-' && *f != '\0' && *f != ']' && f[-2] <= *f) { /* Add all characters from the one before the '-' up to (but not including) the next format char. */ - for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc) + for (fc = f[-2]; fc < *f; ++fc) ((char *)charbuf.scratch.data)[fc] = 1; } else -- 2.17.1