From patchwork Thu Mar 19 07:55:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Terraneo X-Patchwork-Id: 131938 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 50A3B4BBCDA0 for ; Thu, 19 Mar 2026 07:56:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50A3B4BBCDA0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=HOTMAIL.IT header.i=@HOTMAIL.IT header.a=rsa-sha256 header.s=selector1 header.b=LR8ZRsrO X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazolkn19013081.outbound.protection.outlook.com [52.103.35.81]) by sourceware.org (Postfix) with ESMTPS id 123524BBC0F5 for ; Thu, 19 Mar 2026 07:55:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 123524BBC0F5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hotmail.it Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.it ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 123524BBC0F5 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=52.103.35.81 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1773906955; cv=pass; b=BIb6nCIFM9XyhxFYi4TbkhWheZTWaxfwsw62SSaRj4eiO1jjZWFPw95nSz25BfMLRIU6BccFD0cqHa2CY6nvG7Qeem4QnaXGpNI1GmpWDZGSb5LfzjSLADTO19rJw4iSUSDKJI/BaB0cpIcyPxUKABYhNis7x3QuQtmlY3wnE1E= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1773906955; c=relaxed/simple; bh=BvqNINrqvoiPlIQ9hy7r10QmEJd7yoFGXJ/ttK9Ro9Q=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=Usp0cbTgzvaGK+nevrDzOXwnFa5kPWMn8armKEaQ8O5581hSEIZd6TNYuX57xkrWf+sWY02F4ycW98piRiBFyWXZlh20XxWu2fDogJNM5+yQI75/exoJW5/+kPlIcbMZ9BaHItEtEVJa9kHLM5NDg4qTkW2l1xV8dAklCxbArVY= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 123524BBC0F5 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fAlsvfWjm/jpt6yksndxixyHbLluwgkZDQ5obLnMO7gA0tuBDfP9YxNVfj9DpVOQNA85tPvOZMbotdgqH0Y7C6e4l0KaMX93+d/+7NGaw9TID2ZhyHqje2UftF8sf39pxLKO0FKHGjPHPRrBZqVr5jizJd+EiW30KbkADewc4Hf4Q6y90o0YiCWHruM5X9JvXk/IwVMY/I3dldl/m0HMSppRZx2xtYyO5i+3Deppu93qsfuUYwolx8Jxk6J7vfaHRaAaY97x65SJWT5HPOWHZYyPXoIUeYT99z8PYVlqIEAqe0shSr+05UCZqhuOYibpLag62cTbOZkYB/eInzfzqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=IOKkTiyJGs9XnD741nXnZgFA37WlP+DWJOwxgcYSOYA=; b=fTsJJmSMSfKHZJgTBT2vsinsAYPEccjM54q8LKEYdY8NJPpKVV5TihxD2Rveti6kpTbiCt4Szzey1usfsJL5NGGgpmbV9OJVYy57iWZ58EtFVGHP3Kx+IGF8/01qPt2PxxIrVhtvoXComn9hvHeg0SPGkf8i0mNnPgd8J06ep9D9JthR5SiX5DdQkExhDvRCsn4fnIIiuwG7ChGxgzsj5pG2DigmLvcpXhku+QZSTOgmMw3ob9c3FnXd/Y0aKUW4tu5jZSXjv/cAk9dg5T5Bdj4OTDdYZv+dERUPeZH4IfJdcMpPdtz2en3+rBTVF2k6kkHd/e2z79IE0tbcSl6exw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HOTMAIL.IT; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IOKkTiyJGs9XnD741nXnZgFA37WlP+DWJOwxgcYSOYA=; b=LR8ZRsrOfmoSLc49GtDndoz6lz7pZDktAWafwJe8kJlXyVlXYvYAOfg8rQ+UUPtG5FHgjOf0/0/wuDuGYEOWQqfiot19FINs8Xczd5L6bxOMySg4b5M7wK3YkrTduu7Axc0u0P3gGK0xS3WqQlcAXQsFcKmPAIEkhnuHedeSYuiDYT7qYo5JE8YdE2MHcBey9xaQrFfes8LhPKf7z+yoTHQdlN3CZPhcyYubwXG9BqJLH2bNC9X0jSLVXDSKVF6n/YKIkT6AbeNuhMx1ePW/1RsCD8o31l/py3AxiXXUORlUO0g2VJuSzSHB4I5tnRvFi0cIqNlbJWf9bIlYRMH4yQ== Received: from PAVPR08MB8845.eurprd08.prod.outlook.com (2603:10a6:102:2ff::8) by VI1PR08MB5471.eurprd08.prod.outlook.com (2603:10a6:803:137::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.19; Thu, 19 Mar 2026 07:55:46 +0000 Received: from PAVPR08MB8845.eurprd08.prod.outlook.com ([fe80::5b2e:e257:dfac:cc36]) by PAVPR08MB8845.eurprd08.prod.outlook.com ([fe80::5b2e:e257:dfac:cc36%6]) with mapi id 15.20.9723.018; Thu, 19 Mar 2026 07:55:46 +0000 Message-ID: Date: Thu, 19 Mar 2026 08:55:44 +0100 User-Agent: Mozilla Thunderbird Content-Language: en-US To: newlib@sourceware.org Cc: Daniele Cattaneo From: Federico Terraneo Subject: [PATCH] Fix regression in memrchr X-ClientProxiedBy: MI1P293CA0014.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:2::17) To PAVPR08MB8845.eurprd08.prod.outlook.com (2603:10a6:102:2ff::8) X-Microsoft-Original-Message-ID: <08409eda-c4ae-4fb0-8b99-58dace2fb336@hotmail.it> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAVPR08MB8845:EE_|VI1PR08MB5471:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ead3738-9b59-402a-e80e-08de858ced55 X-Microsoft-Antispam: BCL:0; ARA:14566002|12121999013|19110799012|51005399006|5072599009|6092099016|15080799012|8060799015|461199028|23021999003|40105399003|440099028|3412199025; X-Microsoft-Antispam-Message-Info: =?utf-8?q?0dES8niEOMkoLqbYHN4rhxEwdsqCxu8?= =?utf-8?q?A8yiXiC1xdMfabn3YjjXP/fKsckKea5FtvJ6mULhoFe/xPDy9HuYnzuN5JC5n73gW?= =?utf-8?q?B58EOlWSxwxAvRrV2C8QKcZq4pjOqC99faAzKTXPhtWkFwyjIf8J2xXYZvLqUr9FP?= =?utf-8?q?ZbUKFVhnh3rYIvgELMRL5eIAMgKn9p70qlHTbzcWOiMxZC1zubRzBGTgx19bqbyOi?= =?utf-8?q?kZiRvv/IzevYNqYWQs9iFCKpDJ2yvwteGkvd6oYPSK7M9kB0MrgkSWsoPzREY1qPZ?= =?utf-8?q?9/piNLAs2Dp+efu/8iyvNDrcwQH77HixSfFjDYlOjhMOne7ZnKMSE4+FIDSpRfh3O?= =?utf-8?q?SLAQtY5dA8nt4iYZx3uSbpxEdyrtECq0RpijCbuMuuQZ6trcVhSm7TxYESuwtESfF?= =?utf-8?q?B6uURr0+/TID+tDKRmFsP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0dRu5uyAvBN7Bc18/1YV0VoKaUJGWzv0BKHkxjoU3wCd3ON/+wRDE5R3/qmKUuMIE?= =?utf-8?q?BhtKT/znRibhU4u+CknUb7DnAoWZSZQUBMx9eJhhW3+LXAq4kI/fYkLltfBd9s1mn?= =?utf-8?q?sb/gWxauIU6TA7Al00B8Z49PwX0nbMeazI4TnApQ7WVS/h37Ks7gkrXrPGXncRq74?= =?utf-8?q?Tplci0+eTOIAH5X?= X-OriginatorOrg: sct-15-20-9412-4-msonline-outlook-fbb9b.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 2ead3738-9b59-402a-e80e-08de858ced55 X-MS-Exchange-CrossTenant-AuthSource: PAVPR08MB8845.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2026 07:55:46.2887 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5471 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org Hi, while upgrading our toolchain for the Miosix kernel to use the lastest Newlib release, we noticed a regression in memrchr. This issue causes an unaligned memory access resulting in a fault in ARM Cortex M0 microcontrollers. The bug has been introduced in commit c9b74e32892966c8f66280c752181292bc95f690, where the macro UNALIGNED was replaced with a generic one UNALIGNED_X. However, in memrchr.c the UNALIGNED macro was defined as #define UNALIGNED(X) ((long)(X + 1) & (sizeof (long) - 1)) thus checking if X+1 is aligned, not if X is aligned. The replacement macro checks if X is aligned, thus breaking the algorithm. The issue was found by my colleague Daniele Cattaneo. Best regards, Federico Terraneo From ea9b7d9f09d48b2bf88682d47992f5ee0bd4e57d Mon Sep 17 00:00:00 2001 From: Daniele Cattaneo Date: Wed, 18 Mar 2026 17:33:02 +0100 Subject: [PATCH] libc: string: Fix off-by-one alignment bug in memrchr. The loop at line 50 should test the bytes in the buffer, from the end towards the beginning, until it reaches a character whose address is aligned, leaving `src' pointing to the next character to test. However, the loop condition did not test the address of the last character read (`src + 1'), but the address of the next character (`src'). As a consequence, a misaligned address was computed at line 69, because the (aligned) address in `src' is incremented by 1. This bug was originally introduced in commit c9b74e328 during a refactoring of the macros used by string functions. Before the refactoring, the +1 increment in the loop condition was located in the macros specific to memrchr. --- newlib/libc/string/memrchr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newlib/libc/string/memrchr.c b/newlib/libc/string/memrchr.c index 0a0c80fd9..b56e2b476 100644 --- a/newlib/libc/string/memrchr.c +++ b/newlib/libc/string/memrchr.c @@ -47,7 +47,7 @@ memrchr (const void *src_void, unsigned long mask; unsigned int i; - while (UNALIGNED_X(src)) + while (UNALIGNED_X(src + 1)) { if (!length--) return NULL; -- 2.53.0