"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
improve gotwebd_assign_querystring()
To:
gameoftrees@openbsd.org
Date:
Thu, 16 Nov 2023 10:50:10 +0100

Download raw body.

Thread
long story short: while testing -portable for the recent sockets commits
I noticed that gotwebd dies on the first request.

I've already committed a minimal fix: QSELEM__MAX was bigger than the
actual number of elements in the table -- my fault for forgetting to
remove PREVID -- so we read out of bounds and on alpine at least there
happen to be some zeroes... hello strcmp(NULL)!

This would fix it as well, but more importantly would have prevented the
error in the first place.

diff /home/op/w/got
commit - 296611672d3a242111a160c45afb7ac81a01b326
path + /home/op/w/got
blob - 5d1283460327c8a36e76c5f8ed29b5fd573a5ce8
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -559,7 +559,7 @@ gotweb_assign_querystring(struct querystring **qs, cha
 	if (error)
 		return error;
 
-	for (el_cnt = 0; el_cnt < QSELEM__MAX; el_cnt++) {
+	for (el_cnt = 0; el_cnt < nitems(querystring_keys); el_cnt++) {
 		if (strcmp(key, querystring_keys[el_cnt].name) != 0)
 			continue;
 
@@ -645,9 +645,10 @@ qa_found:
 			if ((*qs)->page < 0)
 				(*qs)->page = 0;
 			break;
-		default:
-			break;
 		}
+
+		/* entry found */
+		break;
 	}
 done:
 	return error;
blob - 87f3ab6f87b6831ca7b065a759bc71c251bdcf2d
file + gotwebd/gotwebd.h
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
@@ -416,7 +416,6 @@ enum querystring_elements {
 	INDEX_PAGE,
 	PATH,
 	PAGE,
-	QSELEM__MAX,
 };
 
 enum query_actions {