From: Luca Boccassi Date: Fri, 19 Jan 2024 15:12:49 +0000 (+0000) Subject: cgtop: fix sscanf return code checks X-Git-Tag: v256-rc1~1094 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=204d52c4b79eb19d2919cb5214e999c58a6679c6;p=thirdparty%2Fsystemd.git cgtop: fix sscanf return code checks sscanf can return EOF on error, so check that we get a result instead. CodeQL#2386 and CodeQL#2387 --- diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index e34da7cf728..ca514554408 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -310,9 +310,9 @@ static int process( if (all_unified) { while (!isempty(l)) { - if (sscanf(l, "rbytes=%" SCNu64, &k)) + if (sscanf(l, "rbytes=%" SCNu64, &k) == 1) rd += k; - else if (sscanf(l, "wbytes=%" SCNu64, &k)) + else if (sscanf(l, "wbytes=%" SCNu64, &k) == 1) wr += k; l += strcspn(l, WHITESPACE);