Skip to contentSkip to conversation

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

PATCH New Tzvetomir Stoyanov (VMware) 1 participant 1 message Jan 15, 2021

lore
Share & tools
lore
#0 lore raw

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

Additional check is added to tracefs_instance_file_read_number() API to handle the case when the trace file does not contain any number.

---
 src/tracefs-instance.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/tracefs-instance.c +3 -2
index 97bbb00..b5f8298 100644
@@ -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;
 		}
Signature · 1 line
2.29.2