File: 0006-tracefile_tracecmd-add-null-return-from-fgets-when-E.patch

package info (click to toggle)
idlestat 0.8-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: ansic: 6,539; makefile: 56
file content (36 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
From 84a4c56894001b3241bed81f95b422f662bd21a0 Mon Sep 17 00:00:00 2001
From: Colin Ian King <colin.i.king@gmail.com>
Date: Tue, 13 Dec 2022 16:03:06 +0000
Subject: [PATCH 1/1] tracefile_tracecmd: add null return from fgets when EOF
 occurs
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Add a EOF check on fgets calls.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 tracefile_tracecmd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tracefile_tracecmd.c b/tracefile_tracecmd.c
index eda7b6b..9d38bc4 100644
--- a/tracefile_tracecmd.c
+++ b/tracefile_tracecmd.c
@@ -97,11 +97,12 @@ static struct cpuidle_datas * tracecmd_report_load(const char *filename)
 	/* Number of CPUs */
 	nrcpus = 0;
 	line = fgets(buffer, BUFSIZE, f);
+	if (!line)
+		goto error_close;
 	ret = sscanf(buffer, "cpus=%u", &nrcpus);
 	if (ret != 1)
 		nrcpus = 0;
 	line = fgets(buffer, BUFSIZE, f);
-
 	if (!line)
 		goto error_close;
 
-- 
2.38.1