Index | Thread | Search

From:
Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:
iscsid: fix text_to_bool and text_to_digest handling of errstrp
To:
tech@openbsd.org
Date:
Thu, 23 Jan 2025 11:07:00 +0100

Download raw body.

Thread
I introduced a bug when I refactored text_to_bool and added
text_to_digest.

These function need to set errstr to NULL on successful return, since the
caller does check for that.

I think the netbsd-iscsi-target does not hit these cases since it does not
send any of the affected keys that would trigger the bug.
-- 
:wq Claudio

Index: pdu.c
===================================================================
RCS file: /cvs/src/usr.sbin/iscsid/pdu.c,v
diff -u -p -r1.14 pdu.c
--- pdu.c	22 Jan 2025 10:14:54 -0000	1.14
+++ pdu.c	23 Jan 2025 10:01:40 -0000
@@ -191,14 +191,19 @@ text_to_num(const char *numstr, u_int64_
 int
 text_to_bool(const char *buf, const char **errstrp)
 {
-	int val = 0;
+	int val;
 
 	if (strcmp(buf, "Yes") == 0)
 		val = 1;
-	else if (strcmp(buf, "No") != 0) {
+	else if (strcmp(buf, "No") == 0)
+		val = 0;
+	else {
 		if (errstrp != NULL)
 			*errstrp = "invalid";
+		return 0;
 	}
+	if (errstrp != NULL)
+		*errstrp = NULL;
 	return val;
 }
 
@@ -227,6 +232,8 @@ text_to_digest(const char *buf, const ch
 		}
 		buf = p;
 	}
+	if (errstrp != NULL)
+		*errstrp = NULL;
 	return val;
 }