git: ac930fe19978 - stable/14 - ctld: Use strtonum in lun_set_device_type

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 27 Jan 2026 18:44:36 UTC
The branch stable/14 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=ac930fe19978684a99f1f077d93ea71e0a1c9513

commit ac930fe19978684a99f1f077d93ea71e0a1c9513
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-08-02 14:05:36 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2026-01-27 18:15:58 +0000

    ctld: Use strtonum in lun_set_device_type
    
    This is a direct commit to stable of part of commit
    2e0caa7c7e14d7bdc89ec43be9bc848abe1ca264.  The full commit is not
    merged as it changes the API/ABI of expand_number(3).
---
 usr.sbin/ctld/conf.cc | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 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);
 	}