]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgtop: fix sscanf return code checks
authorLuca Boccassi <bluca@debian.org>
Fri, 19 Jan 2024 15:12:49 +0000 (15:12 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 19 Jan 2024 18:00:23 +0000 (18:00 +0000)
sscanf can return EOF on error, so check that we get a result instead.

CodeQL#2386 and CodeQL#2387

src/cgtop/cgtop.c

index e34da7cf7282e7577dbc0f96b93dc82b5572fe77..ca514554408e8749f6d0e71e0dd63660cf1f3b92 100644 (file)
@@ -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);