Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp150218rdb; Thu, 25 Jan 2024 10:47:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHI1OcdwGDDe5LLd6DJwCVNuwdQQlREZvQZpGFkLTTQrB6vMzuEPYIYh1vhWEv3810ueZga X-Received: by 2002:a50:d505:0:b0:55c:68ca:b782 with SMTP id u5-20020a50d505000000b0055c68cab782mr56079edi.43.1706208428713; Thu, 25 Jan 2024 10:47:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706208428; cv=pass; d=google.com; s=arc-20160816; b=AreFI3MXo22OEA0ATWBom+wLTqGCrpAexCg2lcbhffa6tZpTaUEfmM1tg4N94z8Xyf j1gKNGZJMUgTCOw3Z7fR4yXVvyu3mvS0TqGhcitCQST57Rz6i5G7MzqX0J/DP+jv4KZh Nlu7RdhEs5Qu5LjxTQSNMtlT9ReF2jogxM7hIIQD3qU4sUw2PM5AkRS1ZxpxXvqk3B5s /g7UQiqAlyz9zdJjMa4tdkgjERkk/cCX4HOYULxWt8ktks9cUqGrmbN0ddORZx6pRgnr gVtLkQYn2eJpGez7rI39qYvF3V7aPUb0n118+aseZEjRwRF35W0yb7LIxRNcGu2fwpGR Se7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=mBLIg9GlT5gPcbCunKgcUcrc/pkQPGEuGacL3O8h1U4=; fh=2ka/3EcaDTsu8TuaqtJwTIgbmdiGxrVg9AN4Snp4Pow=; b=myyulVu6xMaa0UPSUZ2rjWZneFBbAt8SZ302rTqRPD8g+qMz+ENYSFEZY4jP6n5GAx +K25sVvcC65j9wgpERyJnEVXDxuE1OaxaZq7aBi/IR7Hb+6G2nxnMDYEvsGw6dF/qylo RZre57b1mxcVyAgSzy/eSLr08bNmgFPZzHL0Q/4+NGRSNFOJqIUwjgv7CErzwtEHEdeh k6wxdXdHBi0YNCX3z2HzfoTG9nHb06E2YOVtQok0Mk66RayNby5k9CZj6wN9F5ltGK13 ajluZR/LkrVrtIzGbCiDZvp25aBclHMrcOGKndGjfTbAida9HSI3LodT9+ugJ/IQlU/1 lGnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@awooo.ru header.s=mail header.b=etKWKqNC; arc=pass (i=1 spf=pass spfdomain=awooo.ru dkim=pass dkdomain=awooo.ru); spf=pass (google.com: domain of linux-kernel+bounces-39146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39146-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e14-20020a50d4ce000000b0055c227b03fbsi5315990edj.519.2024.01.25.10.47.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 10:47:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@awooo.ru header.s=mail header.b=etKWKqNC; arc=pass (i=1 spf=pass spfdomain=awooo.ru dkim=pass dkdomain=awooo.ru); spf=pass (google.com: domain of linux-kernel+bounces-39146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39146-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E40A81F258B3 for ; Thu, 25 Jan 2024 18:46:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 84786135A78; Thu, 25 Jan 2024 18:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=awooo.ru header.i=@awooo.ru header.b="etKWKqNC" Received: from forward100a.mail.yandex.net (forward100a.mail.yandex.net [178.154.239.83]) (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 52C89135A57; Thu, 25 Jan 2024 18:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.83 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706208311; cv=none; b=n8CzeZ5sJOKmGwelz/4IWdH9OZCB7biw8t2wU0eHZQoyMLMkg498NBSGmV5Ozge+zBgoi41YtyPhl2MJ3LHHJafBDB406jOIc65TumgaJW6g9Sae78ogFSyqk0iKbWwUQrWzSw1ovxW3isHyySTmVfaG0Vb5jWocTWB3oxBwaP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706208311; c=relaxed/simple; bh=sknFg9YjLUkGOi+bdNa/wlBuPFMCgxZuVS5giXLTTSM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=M+k+Lm3LRQIVy6OGuFl5rhutWoCfioorXl2PwRKe7+DT4Tc3/BeEpbChvW3XSONIoCSS5F7dIKlaGuRIbjrRawJPT4Edtp1uVhe7jjBdSLkoVRiQJWy7pAQpohfTFmaAyRasRNST+T4Sa3h+Ax+9VD+uEAYV3ZrSKcZMeGjjVwE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=awooo.ru; spf=pass smtp.mailfrom=awooo.ru; dkim=pass (1024-bit key) header.d=awooo.ru header.i=@awooo.ru header.b=etKWKqNC; arc=none smtp.client-ip=178.154.239.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=awooo.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=awooo.ru Received: from mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net [IPv6:2a02:6b8:c15:2c95:0:640:f90:0]) by forward100a.mail.yandex.net (Yandex) with ESMTPS id 1320046C82; Thu, 25 Jan 2024 21:44:58 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id siZhwt2CbeA0-zVloaVIl; Thu, 25 Jan 2024 21:44:57 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=awooo.ru; s=mail; t=1706208297; bh=mBLIg9GlT5gPcbCunKgcUcrc/pkQPGEuGacL3O8h1U4=; h=Cc:To:Message-Id:Date:Subject:From; b=etKWKqNCciYFq48C5RCbkV8Nqurj2lGteP1xEwvnIaqRDx4JCF/fPL1w9hKX0Mtxx G33cW4BLK/dPKWPco46uu481BCr4DAmXvPS97xtIUBb0ypJcnU/Y5wnaiqpvSCoOer JLEjE/XbDmwGavdzGx+DzReviIlN17BZ/kBnb3R4= Authentication-Results: mail-nwsmtp-smtp-production-main-67.vla.yp-c.yandex.net; dkim=pass header.i=@awooo.ru From: kotborealis@awooo.ru To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Evgeny Pistun , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] perf data convert: Output empty string for null pointer Date: Thu, 25 Jan 2024 12:44:11 -0600 Message-Id: <20240125184411.30757-1-kotborealis@awooo.ru> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Evgeny Pistun Providing ill-formed input to `perf data conver --to-json` causes it to crash with segmentaton fault. There's a bug in `output_json_string` functon: input string is not validated. This could be reproduced by crafting input that does not specify hostname/os-release/etc, which are written to 'headers' section of outputted json. This patch adds a null pointer check. If `output_json_string` is called with a null pointer, it should output empty string (`""`). Signed-off-by: Evgeny Pistun --- tools/perf/util/data-convert-json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-convert-json.c index 5bb3c2ba9..f8fd22bd7 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -42,7 +42,7 @@ struct convert_json { static void output_json_string(FILE *out, const char *s) { fputc('"', out); - while (*s) { + while (s != NULL && *s) { switch (*s) { // required escapes with special forms as per RFC 8259 -- 2.25.1