From bab356f5a0b8d4a43a71076c2333ff4da7ed737e Mon Sep 17 00:00:00 2001
From: Luca Boccassi <bluca@debian.org>
Date: Fri, 19 Jan 2024 15:12:49 +0000
Subject: [PATCH 0168/1160] 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

(cherry picked from commit 204d52c4b79eb19d2919cb5214e999c58a6679c6)
---
 src/cgtop/cgtop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index e34da7cf72..ca51455440 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);
-- 
2.33.0