1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-03-13 12:58:20 +03:00

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)
(cherry picked from commit bab356f5a0b8d4a43a71076c2333ff4da7ed737e)
(cherry picked from commit b94c2edce8332aa2c7a8592ad044e18ab627f044)
This commit is contained in:
Luca Boccassi 2024-01-19 15:12:49 +00:00 committed by Luca Boccassi
parent e4f9c90dee
commit 436097f8c8

View 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);