From: Alan T. DeKok Date: Thu, 2 Sep 2021 15:01:24 +0000 (-0400) Subject: parse 1h, 1m, etc. correctly X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89a0f00057c7fafbb083878643b598be821f68ef;p=thirdparty%2Ffreeradius-server.git parse 1h, 1m, etc. correctly --- diff --git a/src/lib/util/time.c b/src/lib/util/time.c index 98dc17e3d2d..c01ae3f62db 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -308,6 +308,33 @@ int fr_time_delta_from_str(fr_time_delta_t *out, char const *in, fr_time_res_t h } } + /* + * minutes, hours, or days. + * + * Fractional numbers are not allowed. + * + * minutes / hours / days larger than 64K are disallowed. + */ + if (sec > 65535) { + fr_strerror_printf("Invalid value at \"%s\"", in); + return -1; + } + + if ((p[0] == 'm') && !p[1]) { + *out = sec * 60 * NSEC; + return 0; + } + + if ((p[0] == 'h') && !p[1]) { + *out = sec * 3600 * NSEC; + return 0; + } + + if ((p[0] == 'd') && !p[1]) { + *out = sec * 86400 * NSEC; + return 0; + } + error: fr_strerror_printf("Invalid time qualifier at \"%s\"", p); return -1; @@ -345,34 +372,6 @@ int fr_time_delta_from_str(fr_time_delta_t *out, char const *in, fr_time_res_t h } else if (*end) { p = end; - - /* - * minutes, hours, or days. - * - * Fractional numbers are not allowed. - * - * minutes / hours / days larger than 64K are disallowed. - */ - if (sec > 65535) { - fr_strerror_printf("Invalid value at \"%s\"", in); - return -1; - } - - if ((p[0] == 'm') && !p[1]) { - *out = sec * 60 * NSEC; - return 0; - } - - if ((p[0] == 'h') && !p[1]) { - *out = sec * 3600 * NSEC; - return 0; - } - - if ((p[0] == 'd') && !p[1]) { - *out = sec * 86400 * NSEC; - return 0; - } - goto error; } else {