linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent
@ 2022-09-30 11:09 Michael Petlan
  2022-09-30 11:10 ` [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning Michael Petlan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michael Petlan @ 2022-09-30 11:09 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt

Hello.

When rebasing to libtraceevent-1.5.3 in RHEL, Coverity has found some
issues. I have tried to fix them. Could you please have a look at the
patches attached?

Thank you.

Michael

Michael Petlan (3):
  libtraceevent: Fix uninitialized has_0x compiler warning
  libtraceevent: Fix check-after-deref coverity flaw
  libtraceevent: Fix Branch condition garbage value compiler warning

 src/event-parse.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

-- 
2.18.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning
  2022-09-30 11:09 [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Michael Petlan
@ 2022-09-30 11:10 ` Michael Petlan
  2022-09-30 11:10 ` [PATCH 2/3] libtraceevent: Fix check-after-deref coverity flaw Michael Petlan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Petlan @ 2022-09-30 11:10 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt

Initialize has_0x in order to supress the following compiler warning:

  event-parse.c:5654:20: warning: 'has_0x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   5654 |                 if (has_0x)
        |                    ^
  event-parse.c:5619:14: note: 'has_0x' was declared here
   5619 |         bool has_0x;
        |              ^~~~~~

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
 src/event-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/event-parse.c b/src/event-parse.c
index 980e980..edf990a 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -5657,7 +5657,7 @@ static inline void print_field(struct trace_seq *s, void *data, int size,
 	struct tep_print_parse *start_parse;
 	struct tep_print_parse *parse;
 	struct tep_print_arg *arg;
-	bool has_0x;
+	bool has_0x = false;
 
 	parse = parse_ptr ? *parse_ptr : event->print_fmt.print_cache;
 
-- 
2.18.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] libtraceevent: Fix check-after-deref coverity flaw
  2022-09-30 11:09 [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Michael Petlan
  2022-09-30 11:10 ` [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning Michael Petlan
@ 2022-09-30 11:10 ` Michael Petlan
  2022-09-30 11:10 ` [PATCH 3/3] libtraceevent: Fix Branch condition garbage value compiler warning Michael Petlan
  2022-10-20 19:15 ` [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Petlan @ 2022-09-30 11:10 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt

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 --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);
-- 
2.18.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] libtraceevent: Fix Branch condition garbage value compiler warning
  2022-09-30 11:09 [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Michael Petlan
  2022-09-30 11:10 ` [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning Michael Petlan
  2022-09-30 11:10 ` [PATCH 2/3] libtraceevent: Fix check-after-deref coverity flaw Michael Petlan
@ 2022-09-30 11:10 ` Michael Petlan
  2022-10-20 19:15 ` [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Petlan @ 2022-09-30 11:10 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt

If *offset equals to zero, it is zero. If not equals to zero, set it to
zero. In any case, it will be zero, so we can omit the condition and so
get rid of the compiler warning:

  libtraceevent/src/event-parse.c:4064:7: warning[core.uninitialized.Branch]: Branch condition evaluates to a garbage value

Instead, let's rather check the pointers for being NULL, in order to
prevent another warning:

  libtraceevent/src/event-parse.c:4064:7: warning[core.NullDereference]: Dereference of null pointer (loaded from variable 'offset')

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

diff --git a/src/event-parse.c b/src/event-parse.c
index b4094ec..60bf989 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -4073,9 +4073,9 @@ static inline void dynamic_offset_field(struct tep_handle *tep,
 {
 	/* Test for overflow */
 	if (field->offset + field->size > size) {
-		if (*offset)
+		if (offset)
 			*offset = 0;
-		if (*len)
+		if (len)
 			*len = 0;
 		return;
 	}
-- 
2.18.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent
  2022-09-30 11:09 [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Michael Petlan
                   ` (2 preceding siblings ...)
  2022-09-30 11:10 ` [PATCH 3/3] libtraceevent: Fix Branch condition garbage value compiler warning Michael Petlan
@ 2022-10-20 19:15 ` Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2022-10-20 19:15 UTC (permalink / raw)
  To: Michael Petlan; +Cc: linux-trace-devel

On Fri, 30 Sep 2022 13:09:59 +0200
Michael Petlan <mpetlan@redhat.com> wrote:

> Hello.
> 
> When rebasing to libtraceevent-1.5.3 in RHEL, Coverity has found some
> issues. I have tried to fix them. Could you please have a look at the
> patches attached?
> 
> Thank you.

Applied. Thanks Michael!

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-20 19:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-30 11:09 [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Michael Petlan
2022-09-30 11:10 ` [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning Michael Petlan
2022-09-30 11:10 ` [PATCH 2/3] libtraceevent: Fix check-after-deref coverity flaw Michael Petlan
2022-09-30 11:10 ` [PATCH 3/3] libtraceevent: Fix Branch condition garbage value compiler warning Michael Petlan
2022-10-20 19:15 ` [PATCH 0/3] Fix several Coverity andf Clang warnings in libtraceevent Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).