From patchwork Wed Aug 21 23:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Inglis X-Patchwork-Id: 96279 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 03146385E45D for ; Thu, 22 Aug 2024 00:00:07 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by sourceware.org (Postfix) with ESMTPS id 325BD3858435 for ; Wed, 21 Aug 2024 23:59:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 325BD3858435 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=SystematicSW.ab.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=SystematicSW.ab.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 325BD3858435 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=216.40.44.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724284792; cv=none; b=DWKyRA0qhk6AvrgZKM30Bei37AZmJmv302zxtazbN+VmY++xZ74vu30SDbb0PqKYkO4vUqQ+LooBwvPHGlPO+6f2DJpunFumu5fUNRuuuQ/IJ0H8BoHsmrgp8YXkX7op6tGTpCqB6gRmjUSYxVWfAujN9ECTdTFMmxC1Meivfag= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724284792; c=relaxed/simple; bh=wzw0Cy+UNMP2VBF5Gbv5Fz4WNN74A30LVkhG5cQ3awo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=tvT5dlyXf8PdSfFR1rk6ep6btFA8roN6xNp3n0cSxsatbca6HL8WTOF4yiOXjloKHv0rSbPyCMKHnh+Oswc/V03Hn/somi9BuI0PSPXptnBN8PR/y2SOM21ThFHce7TRk2XE6rWMFWyFDOxNGqzdr7H5SxnZEskcsJM2leIrboY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from omf03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AA49D1212AD; Wed, 21 Aug 2024 23:59:24 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: Brian.Inglis@SystematicSW.ab.ca) by omf03.hostedemail.com (Postfix) with ESMTPA id 4390E6000D; Wed, 21 Aug 2024 23:59:23 +0000 (UTC) From: Brian Inglis To: newlib@sourceware.org (Newlib) Subject: [RFC] newlib/libc/include/langinfo.h: nl_langinfo enum off by one error causing pointer overwrite Date: Wed, 21 Aug 2024 17:58:46 -0600 Message-ID: X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 Organization: Systematic Software X-Rspamd-Queue-Id: 4390E6000D X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Stat-Signature: hs7nzydgtktyehk5g9zh8crbuhdh8ugd X-Rspamd-Server: rspamout08 X-Session-Marker: 427269616E2E496E676C69734053797374656D6174696353572E61622E6361 X-Session-ID: U2FsdGVkX18A1wbjFuUqMRcHsnW8YgPP3J2WPhwZo+c= X-HE-Tag: 1724284763-910363 X-HE-Meta: U2FsdGVkX1+guhF9uV2KmsIE0vvPJR/TnW6wQZvZH6CxAKOWKS1fPXVwIOYv15AnHNm36xNa8AKjNef4KNV5N52nE9pRXCdFkYoepxaInceMPRkdABTxVQVktWu5VHheafS57lz1zr1Ah8nrQLTamLOoq+yJ/6z18ldzEZW+G1v55uaCQydZSePv/WGK7Deus6hLxDjq8mmAaqBvgIP3fI6ZiZQ+4YJMdIY9XiTzww0jnesX6Pl3LrvfN6RMWvU/p4/eG5BuAvHozn+9UcuSxAcZLpEdAZdI9xFcYf8/fDrH4p0xAVl1QVMk+sVFtDSSU09iTv7Qepo= X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 if __HAVE_LOCALE_INFO__ is defined, then _NL_MESSAGES_CODESET is defined instead of _NL_CTYPE_CODESET after _NL_CTYPE_MB_CUR_MAX, and _NL_MESSAGES_CODESET is omitted before _NL_MESSAGES_WYESEXPR, resulting in _NL_MESSAGES_WNOSTR pointer being overwritten by _NL_COLLATE_CODESET pointer demonstration of pointer overwrite by nl_langinfo dump program generated with additional langinfo.h hack after fix: $ diff -4 /usr{/src/newlib-cygwin/newlib/libc,}/include/langinfo.h --- /usr/src/newlib-cygwin/newlib/libc/include/langinfo.h 2024-08-21 17:11:00.852069900 -0600 +++ /usr/include/langinfo.h 2024-08-21 16:59:59.609998900 -0600 @@ -301,9 +301,9 @@ enum _NL_MESSAGES_CODESET, _NL_MESSAGES_WYESEXPR, _NL_MESSAGES_WNOEXPR, _NL_MESSAGES_WYESSTR, - _NL_MESSAGES_WNOSTR, +#define _NL_MESSAGES_WNOSTR _NL_MESSAGES_WYESSTR _NL_COLLATE_CODESET, MESSAGES_CODESET UTF-8 MESSAGES_WYESEXPR ^[+1yY] MESSAGES_WNOEXPR ^[-0nN] MESSAGES_WYESSTR yes 79 y 65 e 73 s 0 ^@ 6e n 6f o 0 ^@ 0 ^@ # %hx %C dump COLLATE_CODESET UTF-8 if __HAVE_LOCALE_INFO__ is not defined, then _NL_MESSAGES_CODESET is also not defined, so it is unclear if _NL_MESSAGES_CODESET should be defined to _NL_CTYPE_CODESET if neither __HAVE_LOCALE_INFO__ nor __HAVE_LOCALE_INFO_EXTENDED__ are defined, or added as another field depending on those definitions Signed-off-by: Brian Inglis --- newlib/libc/include/langinfo.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/newlib/libc/include/langinfo.h b/newlib/libc/include/langinfo.h index 41d090d3710e..e383dc59d83f 100644 --- a/newlib/libc/include/langinfo.h +++ b/newlib/libc/include/langinfo.h @@ -179,7 +179,7 @@ enum #ifdef __HAVE_LOCALE_INFO__ _NL_CTYPE_MB_CUR_MAX, - _NL_MESSAGES_CODESET, + _NL_CTYPE_CODESET, #ifdef __HAVE_LOCALE_INFO_EXTENDED__ @@ -298,6 +298,7 @@ enum _NL_MONETARY_WPOSITIVE_SIGN, _NL_MONETARY_WNEGATIVE_SIGN, + _NL_MESSAGES_CODESET, _NL_MESSAGES_WYESEXPR, _NL_MESSAGES_WNOEXPR, _NL_MESSAGES_WYESSTR,