diff mbox series

[2/3] libtraceevent: Fix check-after-deref coverity flaw

Message ID 20220930111002.6107-3-mpetlan@redhat.com (mailing list archive)
State Accepted
Commit 64480d21046313042d32a96fdf329fb0ee9d58cf
Headers show
Series Fix several Coverity andf Clang warnings in libtraceevent | expand

Commit Message

Michael Petlan Sept. 30, 2022, 11:10 a.m. UTC
Before patch, both arg->bitmask.field and arg->string.field were checked
for being NULL and if yes, some value was assigned to them. The value
was immediately used (dereferenced) and after that, another check for
NULL was performed (the one leading to break command). However, in case
this check would be true, the dereferencing before would have already
caused a crash.

Move the NULL checks before dereferencing the pointers.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 src/event-parse.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/src/event-parse.c b/src/event-parse.c
index edf990a..b4094ec 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -4623,10 +4623,10 @@  static void print_str_arg(struct trace_seq *s, void *data, int size,
 	case TEP_PRINT_STRING: {
 		if (!arg->string.field) {
 			arg->string.field = tep_find_any_field(event, arg->string.string);
+			if (!arg->string.field)
+				break;
 			arg->string.offset = arg->string.field->offset;
 		}
-		if (!arg->string.field)
-			break;
 		dynamic_offset_field(tep, arg->string.field, data, size, &offset, &len);
 		/* Do not attempt to save zero length dynamic strings */
 		if (!len)
@@ -4640,10 +4640,10 @@  static void print_str_arg(struct trace_seq *s, void *data, int size,
 	case TEP_PRINT_BITMASK: {
 		if (!arg->bitmask.field) {
 			arg->bitmask.field = tep_find_any_field(event, arg->bitmask.bitmask);
+			if (!arg->bitmask.field)
+				break;
 			arg->bitmask.offset = arg->bitmask.field->offset;
 		}
-		if (!arg->bitmask.field)
-			break;
 		dynamic_offset_field(tep, arg->bitmask.field, data, size, &offset, &len);
 		print_bitmask_to_seq(tep, s, format, len_arg,
 				     data + offset, len);