Skip to contentSkip to conversation

idlestat: minor fix for EOF checking

PATCH New Colin Ian King 1 participant 2 messages Dec 13, 2022 Kernel janitors

lore
Share & tools
lore
#0 lore raw

cover idlestat: minor fix for EOF checking

Using static analysis with clang-scan I found a potential EOF not being checked in a fgets call in idlestat. Fix this.

Colin Ian King (1):
tracefile_tracecmd: add null return from fgets when EOF occurs

 tracefile_tracecmd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/1 tracefile_tracecmd: add null return from fgets when EOF occurs

Add a EOF check on fgets calls.

---
 tracefile_tracecmd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tracefile_tracecmd.c +2 -1
index eda7b6b..9d38bc4 100644
@@ -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;
 
Signature · 1 line
2.38.1