Download raw body.
gotwebd: fix cmdline_symset
On Mon, Sep 05, 2022 at 07:58:19PM +0200, Omar Polo wrote:
> On 2022/09/05 19:53:19 +0200, Theo Buehler <tb@theobuehler.org> wrote:
> > On Mon, Sep 05, 2022 at 07:49:37PM +0200, Omar Polo wrote:
> > > 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.
> >
> > Looks like a job for strndup().
>
> yeah, that's an option too.
ok
> 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,15 @@ 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 = strndup(s, val - s);
> if (sym == NULL)
> - fatal("%s: malloc", __func__);
> + fatal("%s: strndup", __func__);
>
> - memcpy(&sym, s, len);
> -
> ret = symset(sym, val + 1, 1);
> free(sym);
>
>
>
gotwebd: fix cmdline_symset