sscanf can return EOF on error, so check that we get a result instead. (cherry picked from commit a44311428a99003d4d40591cdb023c6d253efd94)
31 lines
1.2 KiB
Diff
31 lines
1.2 KiB
Diff
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] 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 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);
|