Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1484847rdb; Sat, 18 Nov 2023 20:13:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEY9yzPURyItJQFUwW2UTarBNj+m0RZupQ1BpdD3Wu9Rgn4xK7oRwXUdCXGWcZQMpgrDLt X-Received: by 2002:a05:6871:8914:b0:1e9:54ef:4806 with SMTP id ti20-20020a056871891400b001e954ef4806mr4645583oab.9.1700367200791; Sat, 18 Nov 2023 20:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700367200; cv=none; d=google.com; s=arc-20160816; b=HAriwUF7NwZD/tyBNlmRwGkGrGVLkH2OAXX47/wOXC1C+H6WGFKrW5IjN9aN0EDM7X m7aDs0CMt3kjuhIAMyNjxfYmhD3JOgQtXXHJiNcwLfCH4bD4xNukvW0zRojI+xzkqgkE aLqjrLTQ9qBnHtiySynpvJe5abJ4RicmL4KsuGJ8WKlA4wSsVrGZndLfwCB0o8PFWpZm RzbjlSgXxChDRlYNo63DtfXPM0M/2FuuCLsR90rcRwBqLmo4dgJwPJOfjeBnjZVYE1ss gB00J8v/B//MruNs3Tod2C1jZquRiNY/LVO3OaOIzKc5aT+J23h8v8E/8tzUj1UrSceP PBgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SOgwgaiftsipEDq0IwhuZKtoSJ1SnhGvWaa7wLnN7nQ=; fh=fUYaAdq5ulPQyDeThzvHIhvtk0akiBvGs51/ze/nQlU=; b=KzevY0GglMo7oHWuyVex1ldoYadPcOEXucLckFGgf4W9PAbfaRa23Om9tqPg3imAS/ eptiP4QwHaFUo7LjL0ZsTev3yFeIyzNgOVFgnEZP61eKBBTKqA5lp1lEQMaYDYY+zKVB hc7sdzkUQH83UkBfqtmI9vaVa14R/izME7jGuOjXYULJ4vNRIawh0/BOU63e/K/B4Tb0 V6mZsNOTq4J7H50pc5mm9vLnW02go1EVBkqm6W2pSNdYWnxDDoR00DKL+7JC6S0nv8Fb 81J621m/2kXEU5N+AXwGDAaF2V4I7NAyxLAp2g80AkO/xmelFE2uTc7fNPKC1KVjDYGj JcIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SPJuJR8x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t24-20020a1709028c9800b001c9c83947d1si5218445plo.645.2023.11.18.20.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 20:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SPJuJR8x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5B4618053C72; Sat, 18 Nov 2023 20:13:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjKSENN (ORCPT + 99 others); Sat, 18 Nov 2023 23:13:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjKSENM (ORCPT ); Sat, 18 Nov 2023 23:13:12 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77463182; Sat, 18 Nov 2023 20:13:07 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b2ea7cca04so2275973b6e.2; Sat, 18 Nov 2023 20:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700367187; x=1700971987; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SOgwgaiftsipEDq0IwhuZKtoSJ1SnhGvWaa7wLnN7nQ=; b=SPJuJR8x2NUhyeYcq97FMH9GqKa1kE93ufqZWHJ4HQvf91fOqxdMUeGOnz0wsQO2DN i3DRPoaIwlPdKvZOb59HOr9lJCqrmnJ1Ye7YYPEJZrBK55olobz5hlZ4Ap4Lg9wyMzO7 QZ+ASbZIRQhgqL2Du1PonqHTuUYaB5al9Rqe8gxOMnSyE93qVhc/+ZDgP07sjUkRtD8t KN8j2fojLijKH3ZsXlQBm0GsxJqXpyR6bgWXNX4KBo6sgaHqZidYtfpgXWrT+vj2pBbg vor2S6HH3kX3CoBs3iRvlvkxIo7HEhObU2ylu7YPLDPiXfSPgQXjktLG/qqyIQCaayM4 Tl3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700367187; x=1700971987; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SOgwgaiftsipEDq0IwhuZKtoSJ1SnhGvWaa7wLnN7nQ=; b=afabjw/Tj/ckQcT92Dq8cbB97mI980S7zCpgQoeQOXPkAlWKJfwfRK59u9nPPOCFe1 L6getlR7Zc4Rb9AmUltC39ifHzyshb/yqgwGT6zlqPgFQgHs4uawUfxeKEJ94w/Oz0Ky /tgvPi2qnu3d6jirt2EBZj2oTOyhcpaukdhdU/YmExlVJaAJizqaeqxkOeb0swy/LwLz baQIZAaV/yjR1xvHuhpXjZjuiOMpsrDQIF6R/KCD+fa3nT3AGtMfUkOY6wfudu44e18R eY9Q5Sg9Z3WSREj2JRiYgW/xGN51nXGvsFlzri0NGQPIWkP+kA/t3lwpuB1Uh9AypzMM j8UQ== X-Gm-Message-State: AOJu0YwIuAUEB5bp83yuERWW1BmImUd0YbLTsoCwWo+kEPbaMi/cA58m sU2WTRbVR9/i6BQPYD2y+cw= X-Received: by 2002:a05:6808:1410:b0:3b2:e536:a442 with SMTP id w16-20020a056808141000b003b2e536a442mr5993983oiv.16.1700367186570; Sat, 18 Nov 2023 20:13:06 -0800 (PST) Received: from DESKTOP-NK4TH6S.localdomain ([220.72.86.144]) by smtp.gmail.com with ESMTPSA id it18-20020a056a00459200b006c6f668c90bsm3724360pfb.134.2023.11.18.20.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 20:13:06 -0800 (PST) From: Paran Lee To: Namhyung Kim , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Sean Christopherson , Li Dong Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, shjy180909@gmail.com, austindh.kim@gmail.com, honggyu.kp@gmail.com, Paran Lee Subject: [PATCH V2] perf script python: Fail check on dynamic allocation Date: Sun, 19 Nov 2023 13:09:44 +0900 Message-Id: <20231119040943.13500-1-p4ranlee@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 18 Nov 2023 20:13:17 -0800 (PST) Add PyList_New() Fail check in get_field_numeric_entry() function and dynamic allocation checking for set_regs_in_dict(), python_start_script(). Signed-off-by: Paran Lee Reviewed-by: Seonghee Jin --- .../util/scripting-engines/trace-event-python.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 94312741443a..f96968ba371f 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -353,6 +353,8 @@ static PyObject *get_field_numeric_entry(struct tep_event *event, if (is_array) { list = PyList_New(field->arraylen); + if (!list) + Py_FatalError("couldn't create Python list"); item_size = field->size / field->arraylen; n_items = field->arraylen; } else { @@ -754,7 +756,7 @@ static void regs_map(struct regs_dump *regs, uint64_t mask, const char *arch, ch } } -static void set_regs_in_dict(PyObject *dict, +static int set_regs_in_dict(PyObject *dict, struct perf_sample *sample, struct evsel *evsel) { @@ -770,6 +772,8 @@ static void set_regs_in_dict(PyObject *dict, */ int size = __sw_hweight64(attr->sample_regs_intr) * 28; char *bf = malloc(size); + if (!bf) + return -1; regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size); @@ -781,6 +785,8 @@ static void set_regs_in_dict(PyObject *dict, pydict_set_item_string_decref(dict, "uregs", _PyUnicode_FromString(bf)); free(bf); + + return 0; } static void set_sym_in_dict(PyObject *dict, struct addr_location *al, @@ -920,7 +926,8 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->cyc_cnt)); } - set_regs_in_dict(dict, sample, evsel); + if (!set_regs_in_dict(dict, sample, evsel)) + Py_FatalError("Failed to setting regs in dict"); return dict; } @@ -1918,12 +1925,18 @@ static int python_start_script(const char *script, int argc, const char **argv, scripting_context->session = session; #if PY_MAJOR_VERSION < 3 command_line = malloc((argc + 1) * sizeof(const char *)); + if (!command_line) + return -1; + command_line[0] = script; for (i = 1; i < argc + 1; i++) command_line[i] = argv[i - 1]; PyImport_AppendInittab(name, initperf_trace_context); #else command_line = malloc((argc + 1) * sizeof(wchar_t *)); + if (!command_line) + return -1; + command_line[0] = Py_DecodeLocale(script, NULL); for (i = 1; i < argc + 1; i++) command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); -- 2.25.1