From patchwork Fri Sep 30 11:10:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Petlan X-Patchwork-Id: 12995263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD3ABC433F5 for ; Fri, 30 Sep 2022 11:22:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232185AbiI3LWC (ORCPT ); Fri, 30 Sep 2022 07:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbiI3LVW (ORCPT ); Fri, 30 Sep 2022 07:21:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2FD1A3D2F for ; Fri, 30 Sep 2022 04:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664536210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=MkJBb6qEyiH1ZELOzZazlE+GwbqiTs5nWcOyNA2hsvM=; b=M8ogQCq+5ztN7CNxfs1IW0XtZxgfX3QxFVpE4JWlN/1px28Vycq4jMU29ult3hhKZHHPfN 63Qe2ghSk8zCzoLkyk050blHH3ZeHlyRrvJKnpGeCHNjAtsUa485mtKZi//s/WZMR+T/AX Yc1KGXU5Xm4isJv4FVL8JAsS5mJRAaA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-287-mjXyYsvGNYiI2T6KHfhuYQ-1; Fri, 30 Sep 2022 07:10:07 -0400 X-MC-Unique: mjXyYsvGNYiI2T6KHfhuYQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 368C8805AC5; Fri, 30 Sep 2022 11:10:07 +0000 (UTC) Received: from Diego.redhat.com (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6459CC15BA4; Fri, 30 Sep 2022 11:10:06 +0000 (UTC) From: Michael Petlan To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org Subject: [PATCH 1/3] libtraceevent: Fix uninitialized has_0x compiler warning Date: Fri, 30 Sep 2022 13:10:00 +0200 Message-Id: <20220930111002.6107-2-mpetlan@redhat.com> In-Reply-To: <20220930111002.6107-1-mpetlan@redhat.com> References: <20220930111002.6107-1-mpetlan@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 --- 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; From patchwork Fri Sep 30 11:10:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Petlan X-Patchwork-Id: 12995264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42348C4332F for ; Fri, 30 Sep 2022 11:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbiI3LWD (ORCPT ); Fri, 30 Sep 2022 07:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbiI3LV1 (ORCPT ); Fri, 30 Sep 2022 07:21:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80FE2AB4EC for ; Fri, 30 Sep 2022 04:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664536211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=2LPmTYz4Cmgh15hlecEwhMtP4kEDxI4VdFvkwWSjP+c=; b=bTKbS8vaiWvxUwmGc7VVFgJgU+BLKTnoBI9b3aptNnjXKy55SQ0wc2oUYZ1oSGPZzZNXmG 8aFE6Dp7q2VAJCucAR0cr3zh7OcRsnshLHq8/llMFam2Ons9c+HwlZyJJt05+PNKPPe714 +HSb889IwvS6F5+FLDJSPjvwCPU+oTc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-235-15TL3CPpNFePnxQ1JfvLJg-1; Fri, 30 Sep 2022 07:10:09 -0400 X-MC-Unique: 15TL3CPpNFePnxQ1JfvLJg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFF79811E67; Fri, 30 Sep 2022 11:10:08 +0000 (UTC) Received: from Diego.redhat.com (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5C39C15BA4; Fri, 30 Sep 2022 11:10:07 +0000 (UTC) From: Michael Petlan To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org Subject: [PATCH 2/3] libtraceevent: Fix check-after-deref coverity flaw Date: Fri, 30 Sep 2022 13:10:01 +0200 Message-Id: <20220930111002.6107-3-mpetlan@redhat.com> In-Reply-To: <20220930111002.6107-1-mpetlan@redhat.com> References: <20220930111002.6107-1-mpetlan@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 --- 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); From patchwork Fri Sep 30 11:10:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Petlan X-Patchwork-Id: 12995265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C72C43217 for ; Fri, 30 Sep 2022 11:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232498AbiI3LWD (ORCPT ); Fri, 30 Sep 2022 07:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232556AbiI3LV2 (ORCPT ); Fri, 30 Sep 2022 07:21:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A8C0E0045 for ; Fri, 30 Sep 2022 04:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664536216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=TqBotxjNdrk9YiwRDsRD9Eq1UXIEKD2SVn4A/RFkruE=; b=AnKQlHw4gZSvGe+Hgp8SgToiT8IrskdbT+55dxnBatS9a8Ok4cPEBnS62EuFYrLr5sou8i xFsbw3vSYrfdAr27xIlAFSh9+HcOy3mbG0sJdHxK39wPifpw9+cu4BKeZZNchqk3yEnlJf vA5EqkAsQah75wYdUlGUDjIgBMV/ff0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-632-_ieKqhl8Ox6ky3nX12T9KA-1; Fri, 30 Sep 2022 07:10:12 -0400 X-MC-Unique: _ieKqhl8Ox6ky3nX12T9KA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8363F380393D; Fri, 30 Sep 2022 11:10:10 +0000 (UTC) Received: from Diego.redhat.com (unknown [10.39.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72735C15BA4; Fri, 30 Sep 2022 11:10:09 +0000 (UTC) From: Michael Petlan To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org Subject: [PATCH 3/3] libtraceevent: Fix Branch condition garbage value compiler warning Date: Fri, 30 Sep 2022 13:10:02 +0200 Message-Id: <20220930111002.6107-4-mpetlan@redhat.com> In-Reply-To: <20220930111002.6107-1-mpetlan@redhat.com> References: <20220930111002.6107-1-mpetlan@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 --- 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; }