From nobody Mon Aug 04 17:25:45 2025 X-Original-To: dev-commits-src-main@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 4bwk3b3kYMz63H5j; Mon, 04 Aug 2025 17:25:47 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 "smtp.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bwk3b0jzmz43LB; Mon, 04 Aug 2025 17:25:47 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754328347; 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: in-reply-to:in-reply-to:references:references; bh=DERU+XWQfzaD2Mk6lv9ubRecy+M1rrWYEvkeIo+ZKTI=; b=yJAtBM/WU/s53ZTXog3fscoujCktR+c6ZIHH4VO+5/lumbbnDALpHe2pGeyCwEdyQYQENz qR5KKqnHOdatcXFuxvKz2JgrOvVN6Dc7ylvtZ17vFyVWsj+1+J8aUAgRlCFzJ7+EngrSAf drcyWgc0i/i/+pzl8cU32OyiGmWtbVH0slqOP22+h4jMLymTRO7j5kFSNCWCqicIQk+QOH HwvjqKOJ5563MDI9uTYsRlnKGupzm1shWuuijx+bt7kgcd93+Vkgw/jHiGSJxqT3Cyyw4P eSwVUoE0PENSbgDdLzvpKe4IOcfFj96PguUN43nunoo4ddeMZjg06S05a2z/bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754328347; 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: in-reply-to:in-reply-to:references:references; bh=DERU+XWQfzaD2Mk6lv9ubRecy+M1rrWYEvkeIo+ZKTI=; b=YKKFkd8YDD1AR4D1KfdPADg8fVHyuI0t7eZ9MvocJJsuvv30AWxeT7WvZU096vTJgeFUm+ 8bl7TTGme88dAU626ornTMUn/R19/JxY2ERT3rsGEYXnpxKRHKOeOuv1wBw4wQQBha2GqX 8qjuQnkFg4wzajPKFIObRo4GliSKw15NkTzUw3ahjVSBpHvnFVyrwVOzZxBdYTB1PIoTSS ihmPeUM1eWictBFVn1RK4PBOy/kli+msKnHwJGWRCvKGtmHb2xfuNP2FoLG37QWDUfw0PK qhGAiz7HLpIeyPInND5grERDNGhnwWHnR+yaZg2NA9ViRErnyIhgYaWNwXQHCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754328347; a=rsa-sha256; cv=none; b=x8E9Uxk5S5AUtlV0VX/AjJhAQsf5v7sqrZyAv1Lru02EpxYlxciDdI+kUN97tx7ptMhpfB 6HscXPYoKuDa+cFc4udCYaBt8WehnzJXHSuaNWkcDv60oPCXe8L8tw/OlA9L2c0dDRwiYh NAZbkMf+CO2wm8BkPIH/sDuQj9FiJcxkL9mGWU2gI/s77lQkZ4VksJsoJv0KqyBMceNXic 3QT7yS2VFUa4tFodbyp4ud0OencsxTWNAYneVPDPVygoSeH+jUB9Hcg6rnzopdv3O6PoFh v0y/8Sgfb0r6zjcTDLdmEVckwR7M27Drj/8aGvAsZi5EXdbzsxBEOQFlHC08rg== Received: from [IPV6:2601:5c0:4202:5670:3cb2:220f:177b:6972] (unknown [IPv6:2601:5c0:4202:5670:3cb2:220f:177b:6972]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4bwk3Z5by1zF8S; Mon, 04 Aug 2025 17:25:46 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: Date: Mon, 4 Aug 2025 13:25:45 -0400 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: git: 2e0caa7c7e14 - main - libutil: Really fix expand_number(3) Content-Language: en-US To: =?UTF-8?Q?Dag-Erling_Sm=C3=B8rgrav?= , src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org References: <202508021406.572E6Y5t034393@gitrepo.freebsd.org> From: John Baldwin In-Reply-To: <202508021406.572E6Y5t034393@gitrepo.freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/2/25 10:06, Dag-Erling Smørgrav wrote: > The branch main has been updated by des: > > URL: https://cgit.FreeBSD.org/src/commit/?id=2e0caa7c7e14d7bdc89ec43be9bc848abe1ca264 > > commit 2e0caa7c7e14d7bdc89ec43be9bc848abe1ca264 > Author: Dag-Erling Smørgrav > AuthorDate: 2025-08-02 14:05:36 +0000 > Commit: Dag-Erling Smørgrav > CommitDate: 2025-08-02 14:05:36 +0000 > > libutil: Really fix expand_number(3) > > It is unclear whether this function was originally intended to support > negative numbers. The original implementation used signed integers, > but actually giving it a negative number as input would have invoked > undefined behavior, and the comments (since removed) only mentioned > positive numbers. Fifteen years ago, I “fixed” this by changing the > type from signed to unsigned. However, it would still have accepted > an input with a leading minus sign (though it would have returned its > absolute value). Fifteen years on, change the type back to signed and > fix the logic so it correctly handles both positive and negative > numbers without invoking undefined behavior. This makes it a better > match for humanize_number(3), which it is supposed to complement. > > Fixes: bbb2703b4f46 > Reviewed by: jhb > Differential Revision: https://reviews.freebsd.org/D51542 > --- > lib/libutil/expand_number.3 | 56 +++++++++++++++++++------------ > lib/libutil/expand_number.c | 82 ++++++++++++++++++++++++++++++++++----------- > lib/libutil/libutil.h | 2 +- > usr.sbin/ctld/conf.cc | 12 ++++--- > usr.sbin/ctld/parse.y | 26 +++++++------- > 5 files changed, 118 insertions(+), 60 deletions(-) > > diff --git a/usr.sbin/ctld/conf.cc b/usr.sbin/ctld/conf.cc > index e86b44ee5004..f3285ebf9d56 100644 > --- a/usr.sbin/ctld/conf.cc > +++ b/usr.sbin/ctld/conf.cc > @@ -409,7 +409,8 @@ lun_set_blocksize(size_t value) > bool > lun_set_device_type(const char *value) > { > - uint64_t device_type; > + const char *errstr; > + int device_type; > > if (strcasecmp(value, "disk") == 0 || > strcasecmp(value, "direct") == 0) > @@ -421,9 +422,12 @@ lun_set_device_type(const char *value) > strcasecmp(value, "dvd") == 0 || > strcasecmp(value, "dvdrom") == 0) > device_type = T_CDROM; > - else if (expand_number(value, &device_type) != 0 || device_type > 15) { > - log_warnx("invalid device-type \"%s\" for lun \"%s\"", value, > - lun->l_name); > + else { > + device_type = strtonum(value, 0, 15, &errstr); > + if (errstr != NULL) { > + log_warnx("invalid device-type \"%s\" for lun \"%s\"", value, > + lun->l_name); > + } > return (false); This breaks any integer device types. The return (false) should only be used in the error case. I will fix as part of my other ctld changes. -- John Baldwin