From patchwork Mon Jul 29 11:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Haehnel X-Patchwork-Id: 1965965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=mi4V0pxY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org) Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXcLv2XlKz1yf4 for ; Mon, 29 Jul 2024 21:58:15 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 255193535988; Mon, 29 Jul 2024 13:58:12 +0200 (CEST) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=mi4V0pxY; dkim-atps=neutral Received: from mx.kernkonzept.com (serv1.kernkonzept.com [159.69.200.6]) by helium.openadk.org (Postfix) with ESMTPS id 6EFA43533B0D for ; Mon, 29 Jul 2024 13:58:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=Content-Transfer-Encoding:MIME-Version:Message-ID :Date:Subject:Cc:To:From:References:In-Reply-To:Reply-To:Content-Type: Content-ID:Content-Description; bh=l5wKdIE5okL0qY0LtH4yyg5sen5ktbikT4zngRMpFPU=; b=mi4V0pxY9VOtoU/LNnM4E1hBa9 fcgqtVpTPkomzU1T8rmBStRH8oU5TtiJMahBxnYpfBllHOPKXHufD5Ou5wITTKHh1Ln75sZiMgn+e kriB431zy6k6tX4tg3RVxk13RnjrWkjP6hrGSfhDOs+dmEWKujFS689x05rS1l9Yjs9x7wHNOuSAs 89mWT5WwkYYxNn+wE7VkSzqfBbIe1ibGjjRLPzOi00zyLVJ5VFqqWDVJC8RSYUW2FTUcVopdl5FCz ubKWLCOWB5SqTlDQZf+dDbGW3kNkuW8V54DnTj3QfqS8wTQOMXhB+PaJX7yJehj9+KxvjZDr0Q3WB paW/o9nQ==; Received: from [10.22.3.160] (helo=amethyst.dd1.int.kernkonzept.com) by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) id 1sYP0t-003yHD-2k; Mon, 29 Jul 2024 13:58:03 +0200 From: Marcus Haehnel To: devel@uclibc-ng.org Date: Mon, 29 Jul 2024 13:58:02 +0200 Message-ID: <20240729115804.30385-1-marcus.haehnel@kernkonzept.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Message-ID-Hash: HDF32KYHYC6P6SMW35YG4K226IJAYMGB X-Message-ID-Hash: HDF32KYHYC6P6SMW35YG4K226IJAYMGB X-MailFrom: marcus.haehnel@kernkonzept.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Frank Mehnert , Marcus Haehnel X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH] iconv: fix parameter type of utf8seq_is_{overlong,surrogate,illegal} List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Frank Mehnert Use `unsigned char *s` rather than `char *s`. First, this fixes compiler warnings when these functions are called from utf8dec_wchar() passing the `in` pointer of type `unsigned char *`. Second, these functions are always called with characters >= 0x80 so the sign bit is set. Shifting right a negative signed value will insert `1` from the left side, so `foo >> 1` where foo is negative will always have the sign bit set. So at least "case 2" would never return true. There is a similar problem with tests like (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF) This condition is always false with `char *s`. Signed-off-by: Marcus Haehnel --- libiconv/iconv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libiconv/iconv.c b/libiconv/iconv.c index 6876ab5f7..095932fd6 100644 --- a/libiconv/iconv.c +++ b/libiconv/iconv.c @@ -242,7 +242,7 @@ static inline int utf8enc_wchar(char *outb, wchar_t c) } } -static inline int utf8seq_is_overlong(char *s, int n) +static inline int utf8seq_is_overlong(unsigned char *s, int n) { switch (n) { @@ -268,12 +268,12 @@ static inline int utf8seq_is_overlong(char *s, int n) return 0; } -static inline int utf8seq_is_surrogate(char *s, int n) +static inline int utf8seq_is_surrogate(unsigned char *s, int n) { return ((n == 3) && (*s == 0xED) && (*(s+1) >= 0xA0) && (*(s+1) <= 0xBF)); } -static inline int utf8seq_is_illegal(char *s, int n) +static inline int utf8seq_is_illegal(unsigned char *s, int n) { return ((n == 3) && (*s == 0xEF) && (*(s+1) == 0xBF) && (*(s+2) >= 0xBE) && (*(s+2) <= 0xBF));