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

From:
Omar Polo <op@omarpolo.com>
Subject:
gotwebd: fix cmdline_symset
To:
gameoftrees@openbsd.org
Date:
Mon, 05 Sep 2022 19:49:37 +0200

Download raw body.

Thread
Thomas reported on IRC that -DFOO=bar crashes gotwebd.  There's a typo
in cmdline_symset where we mangle a pointer instead of writing to what
it points to.  However, also the computed value is wrong (symset gets
called with `sym' being "FOO=" instead of "FOO").

This brings us closer to the usual cmdline_symset.

diff /home/op/w/got
commit - 3d8e0c5ede1a5654397b63a9f483d875543527d5
path + /home/op/w/got
blob - 342886d6f2c8b12ed3548eb39f4ce4d40be487d1
file + gotwebd/parse.y
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -918,19 +918,16 @@ cmdline_symset(char *s)
 {
 	char *sym, *val;
 	int ret;
-	size_t len;
 
 	val = strrchr(s, '=');
 	if (val == NULL)
 		return (-1);
 
-	len = strlen(s) - strlen(val) + 1;
-	sym = malloc(len);
+	sym = calloc(1, val - s + 1);
 	if (sym == NULL)
-		fatal("%s: malloc", __func__);
+		fatal("%s: calloc", __func__);
 
-	memcpy(&sym, s, len);
-
+	memcpy(sym, s, val - s);
 	ret = symset(sym, val + 1, 1);
 	free(sym);