From patchwork Fri Jun 7 16:05:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13690485 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9CB2199235 for ; Fri, 7 Jun 2024 16:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776383; cv=none; b=ouq9BHZfIOBmz5gmFFuwgPaZszJsV8aS6cAY9exAk2jq7u5j5ucfNV7BjJAoUhOBbuowrBLZ68JE/FQR2TaoulKUXbgUb90V8uqx3igFpkXfdW514Kqy2s64LgSzaEQlZadfTpC627RkdAogd3Ef7JE1J9VXAE3Py+N7f+Qr1Mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776383; c=relaxed/simple; bh=+HkE0Yycd2sUvBfzcqe99wHc7UFrOxmnYcm9THzggSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EK32nhEhEnsDPsdEyA+hD62VhrgzB4a0SmRardcgR/DXAR5HGC/rGDq2xKywXlT8urb9lQE0yLZmsnZC3yqPKX9R12vNq2oe7J0KYuUM3OiSypUgEinZyUl5UWf7j/f8pTmS/2+He7MOOTz2N8Vrkxp9h/SxB4PK2++W7SEY9hI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MbK+o+Pj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MbK+o+Pj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717776380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p+CWfzSLt13XdfnfRfCgw1b04HUqNWVPp9FoFuyIy04=; b=MbK+o+PjLHCuqdfSDQxeIgQutRRwqZ1LtIyZdlnLXhGbH8FRCRCGhPv5UFQATv5bW7UYqR AlnXPHMY0x+sapSynQTgjusj/Ms5RCTg3K8Bmq7dPAv98BUbOvoYABmpHsHNVWxk+Mix64 tICLHvSPQc5n51tXydnk0thbM0BmDVY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-iSllhg4cO_-kD6jJkql_zA-1; Fri, 07 Jun 2024 12:05:48 -0400 X-MC-Unique: iSllhg4cO_-kD6jJkql_zA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6263185A780; Fri, 7 Jun 2024 16:05:47 +0000 (UTC) Received: from fedora (unknown [10.43.17.163]) by smtp.corp.redhat.com (Postfix) with SMTP id 225391121337; Fri, 7 Jun 2024 16:05:46 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Fri, 07 Jun 2024 18:05:45 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 1/4] libtraceevent: close shared object in the error path of load_plugin() Date: Fri, 7 Jun 2024 18:05:39 +0200 Message-ID: <20240607160542.46152-2-jmarchan@redhat.com> In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com> References: <20240607160542.46152-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 The handle returned by dlopen() isn't close if an error occures afterward. Call dlclose() in the error path. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- src/event-plugin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/event-plugin.c b/src/event-plugin.c index f42243f..7f94107 100644 --- a/src/event-plugin.c +++ b/src/event-plugin.c @@ -474,7 +474,7 @@ load_plugin(struct tep_handle *tep, const char *path, while (options->name) { ret = update_option(alias, options); if (ret < 0) - goto out_free; + goto out_close; options++; } } @@ -483,13 +483,13 @@ load_plugin(struct tep_handle *tep, const char *path, if (!func) { tep_warning("could not find func '%s' in plugin '%s'\n%s\n", TEP_PLUGIN_LOADER_NAME, plugin, dlerror()); - goto out_free; + goto out_close; } list = malloc(sizeof(*list)); if (!list) { tep_warning("could not allocate plugin memory\n"); - goto out_free; + goto out_close; } list->next = *plugin_list; @@ -501,6 +501,8 @@ load_plugin(struct tep_handle *tep, const char *path, func(tep); return; +out_close: + dlclose(handle); out_free: free(plugin); } From patchwork Fri Jun 7 16:05:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13690482 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37E9C19AA43 for ; Fri, 7 Jun 2024 16:05:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776357; cv=none; b=i1gFCVinwGn99G4OjFfqVhOaV3kzyGuZpegwKo9afareaMJzW6m8QBvcdTi8sJgnE4iBpxKoCzgWlxyfVuVbZhiOOJ/y309jiUs0vjYsJ8OqTQEVPH85Hsb/tMFibM8T5Bxi4ffqneYf5tR09Z9bY1/F9wHrIGNeN++soz4uAgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776357; c=relaxed/simple; bh=vlmqTvB/rVpJ9d42QMAsL6FICRWNRc6Kr/m08Eu2Ueo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eLMnAO8TeTTJbfaCOF0pDk3gXD/hDdfmzKexqsPlpGkeDFhCFICWym9zft4+Vj8m+VpG8x+yohRXAe1YJsYAGvvpbxGDxnWT6ZoQmW79bNKPaMCleQxglVUUHAQYd6fQGLTICcpNSm/TrMyqqnoo46hPoJUsHhXwmM2NPI11Lkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JMzttXzZ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JMzttXzZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717776354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U3hdmgS59moAi7QgEb0UsjD7PlQUjeWMnF7pSp2ll50=; b=JMzttXzZGXfWgBAZqGv3IE9+r8iu1dzMnqKk1dvezjfcJu2Kp1InKAAaKeR/+pDmz4Txxf vFsbQyriYe4JQdI42ZwjKNmmoMMIBgkEM5XakR/QztTgzGRzLfbU3uz9pCtCOTYtb0OFNS 4+GiBIqcSCE4r1/UhQJKeGJ34ve9fHc= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-dH3hPhTtPwuB-MWg78w2LQ-1; Fri, 07 Jun 2024 12:05:52 -0400 X-MC-Unique: dH3hPhTtPwuB-MWg78w2LQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 930AD19560BB; Fri, 7 Jun 2024 16:05:51 +0000 (UTC) Received: from fedora (unknown [10.43.17.163]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 41C271955E80; Fri, 7 Jun 2024 16:05:49 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Fri, 07 Jun 2024 18:05:47 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 2/4] libtraceevent: prevent a memory leak in process_fields() Date: Fri, 7 Jun 2024 18:05:40 +0200 Message-ID: <20240607160542.46152-3-jmarchan@redhat.com> In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com> References: <20240607160542.46152-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 One of the error path after field was allocated go to the wrong label. Go to out_free_field if the allocation of arg fails. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- 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 b625621..9f0522c 100644 --- a/src/event-parse.c +++ b/src/event-parse.c @@ -2963,7 +2963,7 @@ process_fields(struct tep_event *event, struct tep_print_flag_sym **list, char * free_arg(arg); arg = alloc_arg(); if (!arg) - goto out_free; + goto out_free_field; free_token(token); type = process_arg(event, arg, &token); From patchwork Fri Jun 7 16:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13690483 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69889199235 for ; Fri, 7 Jun 2024 16:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776361; cv=none; b=B7UDw+9lBHFnalxTeTj9b0cQFGZkIr+a/oTWCqJ/bmHZP2cQxkrLxH5XOyCYCiib4UXckLt2BcQ75KojzfxbxDHA7TJho4xBj+H1LLturx/yr/DC3CodXGC4xk3xoM/DtAr8imflCpoGpAgV1xaU1m4sxUolS86zKOoYplBvt0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776361; c=relaxed/simple; bh=nruzFuTsBNDXZZiXmfMzJBIVSPP17MfBvbKxVXnoFhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WOlo21xsWhdCUc/I5BFRqqTFXzrcQWgFh5rFofIcLTejSCvZUtgJ7nPCPkemHLf9MVkWWMdM0P+ApgPH8u348tve9UkqIGdC6N35j2Ikq1/NsOKmii0SSdysb/V5e6mbzTfwVqF41mfwtZ/3ZkIx0b47zcGjn7BLynGizWKYuS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Hs/CwTLX; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Hs/CwTLX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717776359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dMdugO/WaTtMBYpR27KdFJufV5lq6opB5QI665paLsQ=; b=Hs/CwTLXuuNIppQERcIta2qIaPpiLkiB7qpW1QSUzowd8SopzW1SBvvGlu/mCWm5FvMkwa hVgv/u7fyBI8HD0RA6GINOY1l3aAigZL13lUQo/cVEh9y1H0XUltsTw5AJqlBYCCXFDmhx LCFlYK6zlJ3DlWaEf0cll+Fw17A6qG8= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-KsLXKJ34NyKeaDhvN2ObDg-1; Fri, 07 Jun 2024 12:05:56 -0400 X-MC-Unique: KsLXKJ34NyKeaDhvN2ObDg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2BD8519560BF; Fri, 7 Jun 2024 16:05:55 +0000 (UTC) Received: from fedora (unknown [10.43.17.163]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id E97231956089; Fri, 7 Jun 2024 16:05:52 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Fri, 07 Jun 2024 18:05:51 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 3/4] libtraceevent: prevent a memory leak in tep_plugin_add_option() Date: Fri, 7 Jun 2024 18:05:41 +0200 Message-ID: <20240607160542.46152-4-jmarchan@redhat.com> In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com> References: <20240607160542.46152-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 If parse_option_name() fails, plugin, which now points to the previous value of option_str isn't freed. Go to out_free if that happen. Fixes a RESOURCE_LEAK error (CWE-772) Signed-off-by: Jerome Marchand --- src/event-plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event-plugin.c b/src/event-plugin.c index 7f94107..c944204 100644 --- a/src/event-plugin.c +++ b/src/event-plugin.c @@ -327,7 +327,7 @@ int tep_plugin_add_option(const char *name, const char *val) return -ENOMEM; if (parse_option_name(&option_str, &plugin) < 0) - return -ENOMEM; + goto out_free; /* If the option exists, update the val */ for (op = trace_plugin_options; op; op = op->next) { From patchwork Fri Jun 7 16:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Marchand X-Patchwork-Id: 13690484 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50418199235 for ; Fri, 7 Jun 2024 16:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776363; cv=none; b=HWuoiSrfIMXH7NB6W54NB2IVZAVqlxxQcQh0f+LioF5/9GsGH//F6pBYSIQvLDvwbJnUbzwvBawq3ip+7oFRw4L0KQakNYt8bCu0UBbVO/bMz4EJMCQcnm7PbkyfUCFxjsgRRsAW226bkwgr2WVFv0eliP+U9JXCkiR0fs2Xo90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776363; c=relaxed/simple; bh=6I45+YL8eVDYaYvFI2kccLgNe4ODj4nmUeQHpqS0Etw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oP2tDOt/szJbnRtIb6mm3YdcM94Eve9j6gkXqyaXgKGkkje6xMJX/SDPsOGzjI/bZp2uw9Cii4EQOLt86ffKCWc961nZveeKyoOFJ80V1auHb8pjofWYJiIqq64Y3Fo6KFYylUzFeY5QVUV4MKUan5RQbgIiHcdW1krKtC926Ug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=b4qtLjWx; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="b4qtLjWx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717776361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JcP3fYm9J0YCatO/9/xelOXZJLvTk/wX8Mun1PO35hw=; b=b4qtLjWxWPSNrXqyjkSNLcEJQiTcHgMe6H0O2tCRWc4gggfVMSpLF4TeTDt+mmiQbOFK05 hb/aGZQXFqxmu8IJ3HPC29kmKM/+/kxI7cj4N/aZ9ZYtd71qe6g+MpasQ6uPMSaued3R6R REPvznMQKnnfNfSc7Zs75x3nUqIm288= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-Ak-8C7lEMteYoFjVJicknw-1; Fri, 07 Jun 2024 12:05:59 -0400 X-MC-Unique: Ak-8C7lEMteYoFjVJicknw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BFDD219560AD; Fri, 7 Jun 2024 16:05:58 +0000 (UTC) Received: from fedora (unknown [10.43.17.163]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 84AFE19560AA; Fri, 7 Jun 2024 16:05:56 +0000 (UTC) Received: by fedora (sSMTP sendmail emulation); Fri, 07 Jun 2024 18:05:55 +0200 From: "Jerome Marchand" To: Linux Trace Devel Cc: Steven Rostedt , Jerome Marchand Subject: [PATCH 4/4] libtraceevent: don't return a pointer to a local variable get_field_str() Date: Fri, 7 Jun 2024 18:05:42 +0200 Message-ID: <20240607160542.46152-5-jmarchan@redhat.com> In-Reply-To: <20240607160542.46152-1-jmarchan@redhat.com> References: <20240607160542.46152-1-jmarchan@redhat.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 The function get_field_str() can return a pointer to string on the stack. Replace it by a global variable. Fixes a RETURN_LOCAL error (CWE-562) Signed-off-by: Jerome Marchand --- src/parse-filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/parse-filter.c b/src/parse-filter.c index e448ee2..f0c0ae1 100644 --- a/src/parse-filter.c +++ b/src/parse-filter.c @@ -1698,6 +1698,8 @@ static int test_num(struct tep_event *event, struct tep_filter_arg *arg, } } +char hex[64]; + static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *record) { struct tep_event *event; @@ -1705,7 +1707,6 @@ static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record * unsigned long long addr; const char *val = NULL; unsigned int size; - char hex[64]; /* If the field is not a string convert it */ if (arg->str.field->flags & TEP_FIELD_IS_STRING) {