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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: fix tp_urlescape() escaping
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Thu, 13 Aug 2026 13:11:49 +0200

Download raw body.

Thread
On Sun, Aug 02, 2026 at 10:28:57PM +0200, Omar Polo wrote:
> spotted while looking for something different in a different repository,
> copy-paste is golden.
> 
> tp_urlescape() is space-padding instead of zero-padding, fix is trivial.
> 
> ok?

ok, nice catch.

I had to revisit the snprintf manual to see what this fix does.

> diff /home/op/w/got
> path + /home/op/w/got
> commit - c3f50630385142d9b8e1f024294037c21ea4ac5c
> blob - a462a35fdd53ed1e7997e205fd621e462ad511bc
> file + template/tmpl.c
> --- template/tmpl.c
> +++ template/tmpl.c
> @@ -83,7 +83,7 @@ tp_urlescape(struct template *tp, const char *str)
>  		if (iscntrl((unsigned char)*str) ||
>  		    isspace((unsigned char)*str) ||
>  		    *str == '\'' || *str == '"' || *str == '\\') {
> -			r = snprintf(tmp, sizeof(tmp), "%%%2X", *str);
> +			r = snprintf(tmp, sizeof(tmp), "%%%02X", *str);
>  			if (r < 0  || (size_t)r >= sizeof(tmp))
>  				return (0);
>  			if (tp_write(tp, tmp, r) == -1)
> 
>