From: Omar Polo Subject: Re: gotd.conf: adds time suffixes to timeouts To: Stefan Sperling Cc: gameoftrees@openbsd.org Date: Tue, 03 Jan 2023 16:11:56 +0100 On 2023/01/03 15:17:29 +0100, Stefan Sperling wrote: > On Tue, Jan 03, 2023 at 10:48:01AM +0100, Omar Polo wrote: > > I had something like this lying around in a private parse.y, would it > > be useful for gotd too? It just allows for a slightly more nice > > timeout definition, which is quite niche. > > I like this. ok when adding the check for the multiplication overflow (which my private parse.y didn't have) I ended up duplicating some logic from strtonum. no need to check if it's lesser than a value afterwards, strtonum does that for us already. diff /home/op/w/got2 commit - 92c8ec640028151d1e92eaef79c4fcd1365998bc path + /home/op/w/got2 blob - a157b990e93fe1cb15f7ba00f0d218349adca5a2 file + gotd/parse.y --- gotd/parse.y +++ gotd/parse.y @@ -181,7 +181,7 @@ timeout : NUMBER { } $$.tv_usec = 0; - $$.tv_sec = strtonum($1, 0, INT_MAX, &errstr); + $$.tv_sec = strtonum($1, 0, INT_MAX / mul, &errstr); if (errstr) { yyerror("number of %s is %s: %s", type, errstr, $1); @@ -189,13 +189,6 @@ timeout : NUMBER { YYERROR; } - if ($$.tv_sec > INT_MAX / mul) { - yyerror("number of %s is too too large: %s", - type, $1); - free($1); - YYERROR; - } - $$.tv_sec *= mul; free($1); }