diff mbox series

libtracefs: Enhance error checking when reading a number from trace file

Message ID 20210115050349.1193918-1-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit 1a587d350d4c7a42fc9917fd082ee6ddabfe6af4
Headers show
Series libtracefs: Enhance error checking when reading a number from trace file | expand

Commit Message

Tzvetomir Stoyanov (VMware) Jan. 15, 2021, 5:03 a.m. UTC
Additional check is added to tracefs_instance_file_read_number() API to
handle the case when the trace file does not contain any number.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 src/tracefs-instance.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index 97bbb00..b5f8298 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -316,13 +316,14 @@  int tracefs_instance_file_read_number(struct tracefs_instance *instance,
 	long long num;
 	int ret = -1;
 	int size = 0;
+	char *endptr;
 	char *str;
 
 	str = tracefs_instance_file_read(instance, file, &size);
 	if (size && str) {
 		errno = 0;
-		num = strtoll(str, NULL, 0);
-		if (errno == 0) {
+		num = strtoll(str, &endptr, 0);
+		if (errno == 0 && str != endptr) {
 			*res = num;
 			ret = 0;
 		}