From: Thomas Weißschuh Date: Tue, 9 Apr 2024 09:00:08 +0000 (+0200) Subject: logger: rework error handling in logger_gettimeofday() X-Git-Tag: v2.42-start~435^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=564750580b2a78c2f3f0e8d02bdef9503d6b110c;p=thirdparty%2Futil-linux.git logger: rework error handling in logger_gettimeofday() * Fail when LOGGER_TEST_TIMEOFDAY is set to an invalid value * Fail with return -1 and errno, the same as normal gettimeofday() Signed-off-by: Thomas Weißschuh --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index b4a909438..ec1fc8e34 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -154,13 +154,24 @@ static inline int logger_gettimeofday(struct timeval *tv, struct timezone *tz) char *str = getenv("LOGGER_TEST_TIMEOFDAY"); uintmax_t sec, usec; - if (str && sscanf(str, "%ju.%ju", &sec, &usec) == 2) { + if (str) { + if (sscanf(str, "%ju.%ju", &sec, &usec) != 2) + goto err; + tv->tv_sec = sec; tv->tv_usec = usec; - return tv->tv_sec >= 0 && tv->tv_usec >= 0 ? 0 : -EINVAL; + + if (tv->tv_sec >= 0 && tv->tv_usec >= 0) + return 0; + else + goto err; } return gettimeofday(tv, tz); + +err: + errno = EINVAL; + return -1; } static inline char *logger_xgethostname(void)