From nobody Thu Sep 07 14:51:06 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RhMcq3MNBz4snh4; Thu, 7 Sep 2023 14:51:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RhMcq2Ll5z4l89; Thu, 7 Sep 2023 14:51:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694098267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DHRcbgxm1V+n3KIM1FP7pzhwzwOTHUMUtKk1xG+ONq4=; b=pHW9SGH9wxW7Sd5r/sc3FqvAmnfbRT+HI4mDbRUcM7u7YQs3Jp9lAy2XanuQ80m84bx8Z/ BR34532EFr/Kkd1Abl6XDmBfUz7uErWNLsx1y1Mn9Bn1P2d+BPBftiNZ5Dwtg6x2Lqp5k1 SF+avT5TeASvVWmuRPnf182GRWLR6c+uSHasJthYvSFswNTMf1xDTQ3BGnoi9+gSnr8WfP xyb2N6BMRBZwt7u8bFoIQ0H3aWfIgKatyXA81sJCOZWP74A1FxYNQf7vt14koFEp4I+OCh LCt4l/iKILkdiYrTTyHZfcDajmNEFnfO/I8VhQfm5kGd92h/My4EMmgkEemG2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694098267; a=rsa-sha256; cv=none; b=q99xfo8VRQMwS1z92iRG/e4V6eYPTdXl9MSf5rrMKjDIlDsNygoMaD91QhVfiCgI8wXFUW gjpYMsb3eDanfV3x6CHIiHYTguWE7yd72vgSZLFTdGVAclmBciO74dZKK0f+GXwihy9jY3 bpOMGE2qYCN6rOMJyLAmCQ3804Ivjp14QBQR37oPVH+4iAavylZFi6ckYJ3vmW9DIB5Uku wpdIrvwny9Ix8UOQH82fr+J8ugid4bYH8OpSo/dvDsGYtx1H+/wNKgYEKK5tg13KNUCE/Q XSkJ/gllivhKlrNKEy4CEMvWOz2Asy6gUeYNN+/tgFQnOE5kLIsNcpYZrcytRw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694098267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DHRcbgxm1V+n3KIM1FP7pzhwzwOTHUMUtKk1xG+ONq4=; b=phXqUWn8EM0RFLE9I40+YWFY4ow/4emJgi+CMyUUU4loTL643X/fATR07zjbsIBg5xCftV stoncEanIxnEchEvBoMXmYMcBwPfA61xwWhqCTQhZ0rAfYPKT+pZsyUQM1+xJba4/jziqt ZaLwz/bZZ7C34WgB02HfKB2B13PJW+6h3oo3w3s2XrJaWyClzvy/epKfjntIotFvH+PGfe c4tMeMPQR+v42VrqiDr39/0HAPQ8J111BZlvByuSel+FIaJ6V+AwWMyPPO8qnraeggxoCl /4Jg3P0iKCUhbKB2fJYguAgY1F1L0/ZfYzQRtc4kGxXz6IHrNapU2KCTXm5dlw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RhMcq0MCsz13tC; Thu, 7 Sep 2023 14:51:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 387Ep6hW013163; Thu, 7 Sep 2023 14:51:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 387Ep6bx013160; Thu, 7 Sep 2023 14:51:06 GMT (envelope-from git) Date: Thu, 7 Sep 2023 14:51:06 GMT Message-Id: <202309071451.387Ep6bx013160@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 3b95950fa3f4 - stable/13 - libc: Fix parsing of hexadecimal numbers in strtol() family. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3b95950fa3f4e304908cec6818d552db69e2bb64 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=3b95950fa3f4e304908cec6818d552db69e2bb64 commit 3b95950fa3f4e304908cec6818d552db69e2bb64 Author: Dag-Erling Smørgrav AuthorDate: 2023-08-24 21:31:03 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-09-07 09:00:30 +0000 libc: Fix parsing of hexadecimal numbers in strtol() family. This had previously been partly fixed in 2571c7f7200f. MFC after: 1 week Reviewed by: imp, allanjude, emaste Differential Revision: https://reviews.freebsd.org/D41510 (cherry picked from commit b8b6bef43f876a0a0b8c0b4ae65135bcab4c7aa6) --- lib/libc/iconv/_strtol.h | 5 ++++- lib/libc/iconv/_strtoul.h | 5 ++++- lib/libc/locale/wcstoimax.c | 5 ++++- lib/libc/locale/wcstol.c | 7 +++++-- lib/libc/locale/wcstoll.c | 5 ++++- lib/libc/locale/wcstoul.c | 5 ++++- lib/libc/locale/wcstoull.c | 5 ++++- lib/libc/locale/wcstoumax.c | 5 ++++- 8 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lib/libc/iconv/_strtol.h b/lib/libc/iconv/_strtol.h index 786ae2efbaa9..d183edbe8c3a 100644 --- a/lib/libc/iconv/_strtol.h +++ b/lib/libc/iconv/_strtol.h @@ -83,7 +83,10 @@ _FUNCNAME(const char *nptr, char **endptr, int base) c = *s++; } if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || + (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/iconv/_strtoul.h b/lib/libc/iconv/_strtoul.h index 2d5c7776b0e3..eade72e9c2e6 100644 --- a/lib/libc/iconv/_strtoul.h +++ b/lib/libc/iconv/_strtoul.h @@ -79,7 +79,10 @@ _FUNCNAME(const char *nptr, char **endptr, int base) c = *s++; } if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || + (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstoimax.c b/lib/libc/locale/wcstoimax.c index 729800704bef..e7b1c71e5d71 100644 --- a/lib/libc/locale/wcstoimax.c +++ b/lib/libc/locale/wcstoimax.c @@ -78,7 +78,10 @@ wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstol.c b/lib/libc/locale/wcstol.c index a61db0ec8b60..facf2bd9ee35 100644 --- a/lib/libc/locale/wcstol.c +++ b/lib/libc/locale/wcstol.c @@ -63,7 +63,7 @@ wcstol_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int do { c = *s++; } while (iswspace_l(c, locale)); - if (c == '-') { + if (c == L'-') { neg = 1; c = *s++; } else { @@ -72,7 +72,10 @@ wcstol_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, int c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstoll.c b/lib/libc/locale/wcstoll.c index f6de4ca38332..c8cf66c1bb01 100644 --- a/lib/libc/locale/wcstoll.c +++ b/lib/libc/locale/wcstoll.c @@ -78,7 +78,10 @@ wcstoll_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstoul.c b/lib/libc/locale/wcstoul.c index cc9f50fbfbc9..0f6fe4152dea 100644 --- a/lib/libc/locale/wcstoul.c +++ b/lib/libc/locale/wcstoul.c @@ -72,7 +72,10 @@ wcstoul_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstoull.c b/lib/libc/locale/wcstoull.c index a967e1691292..df68c5681433 100644 --- a/lib/libc/locale/wcstoull.c +++ b/lib/libc/locale/wcstoull.c @@ -78,7 +78,10 @@ wcstoull_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16; diff --git a/lib/libc/locale/wcstoumax.c b/lib/libc/locale/wcstoumax.c index a14dca8ba80b..d6e92f4d3305 100644 --- a/lib/libc/locale/wcstoumax.c +++ b/lib/libc/locale/wcstoumax.c @@ -78,7 +78,10 @@ wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr, c = *s++; } if ((base == 0 || base == 16) && - c == L'0' && (*s == L'x' || *s == L'X')) { + c == L'0' && (*s == L'x' || *s == L'X') && + ((s[1] >= L'0' && s[1] <= L'9') || + (s[1] >= L'A' && s[1] <= L'F') || + (s[1] >= L'a' && s[1] <= L'f'))) { c = s[1]; s += 2; base = 16;