Skip to contentSkip to conversation

libtraceevent: Check type string length in eval_type_str()

PATCH New Namhyung Kim 1 participant 1 message May 13, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceevent: Check type string length in eval_type_str()

The pointer type check unconditionally accesses len - 2 and it could be a problem when the given type string broken or malicious. Also the shortest supported type length is 2 (s8 and u8). So let's check the length first to prevent invalid access.

Actually this was found in a fuzzer test.

---
 src/event-parse.c | 4 ++++
 1 file changed, 4 insertions(+)
src/event-parse.c +4 -0
index f862f49..e4b337c 100644
@@ -2437,6 +2437,10 @@ eval_type_str(unsigned long long val, const char *type, int pointer)
 	int len;
 
 	len = strlen(type);
+	if (len < 2) {
+		do_warning("invalid type: %s", type);
+		return val;
+	}
 
 	if (pointer) {
 
Signature · 1 line
2.36.0.550.gb090851708-goog