From 47f514fde6e29137d660c19e6eea0b842d2b03f5 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 10 Feb 2020 14:55:53 +0100 Subject: common: Also protect log_inc_errorcount against counter overflow. * common/logging.c (log_inc_errorcount): Also protect against overflow. (log_error): Call log_inc_errorcount instead of directly bumping the counter. -- We already had an overflow checking for log_error but not for the silent increment function. This is basically the same fix we have in libgpg-error (libgpg-error commit d72c1ddfde09ffa69745ec2439c5a16d15e2202f) Signed-off-by: Werner Koch --- common/logging.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/logging.c b/common/logging.c index c4eaca411..df55e6827 100644 --- a/common/logging.c +++ b/common/logging.c @@ -129,7 +129,9 @@ log_get_errorcount (int clear) void log_inc_errorcount (void) { - errorcount++; + /* Protect against counter overflow. */ + if (errorcount < 30000) + errorcount++; } @@ -932,9 +934,7 @@ log_error (const char *fmt, ...) va_start (arg_ptr, fmt); do_logv (GPGRT_LOG_ERROR, 0, NULL, NULL, fmt, arg_ptr); va_end (arg_ptr); - /* Protect against counter overflow. */ - if (errorcount < 30000) - errorcount++; + log_inc_errorcount (); } -- cgit v1.2.3