Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2590261ybg; Fri, 31 Jul 2020 04:45:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvldrk3albKj2+oyDJ6IrrokVC90vCMPLn/6W1HFmB6E/lLD2bJW4/KLCt2U9gJCguMU/c X-Received: by 2002:a50:8749:: with SMTP id 9mr3532991edv.80.1596195953801; Fri, 31 Jul 2020 04:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596195953; cv=none; d=google.com; s=arc-20160816; b=atkQ29A6iE5BvyGvNM5lK9Y8S3CyMHEqlhyfJ/t0ikYj8Kz17yUnuKoS3QjFFeC1i5 XGy7g02udnR00u+OV4+l2e8qj8hDnpecDD9hDpXpBXMx0Qzi5xTnp3mWcqyVQxTjKJeA f/ZcttoHKyLDe8K50PQKkIqPW2fZA9r9eVwek0+Z+s2ianNCUlRxIbgn6jYESlL+aJnv irnNr+ULmrauP7361VUjtABL4XtoRAsls4GA4MEGmUYkP3vhSSppf2N4GyP0Dk2xgxxu lQdh0L+6tI8l7uM1R62FnS9EgP+6jqvd/I7JKWZqKtOU6Ecswt38Kzu1lQ8GuxN8jWP3 au1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:mime-version:message-id:date:subject :cc:from; bh=+Y7MCxj1QPftZPn59uUmdsydgKHF/R2TVTcLnTfbgG0=; b=REThZGKZSfZbPgN8Wx92RfFZyhkfIyfRwcfSAGiSHLVxjzGqWto3cyVO4DEQ3VERgp 4geuwCJKMzvaHiQONb7EKDcxCcpga8aWJpU+VG1yBXgMSiZLjbl252Mmhs1soBEIjsvV dqX1GzG9pae9Fl9Bw7kUpbpAOdWL/aV+U5e1ZVjCBol+kR3GLQ8II/wtjHq5SnZx0t3G Q5fA7qiVBGIK1aubV6m37F+DUswnt4BCUSdZIkAAwATmf14FMht0B67SJI+Xv2yMC6F5 E+mwbqegCiArdNzar+3YLdrZhouoUlpDqnRZGLJYP8sgIynntaUv3Smh8JLGhALQ0H5z jxOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si4851561eje.672.2020.07.31.04.45.30; Fri, 31 Jul 2020 04:45:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732757AbgGaLnD (ORCPT + 99 others); Fri, 31 Jul 2020 07:43:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:34692 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732734AbgGaLnD (ORCPT ); Fri, 31 Jul 2020 07:43:03 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id C1593DFAFDA3F5F6E2A6; Fri, 31 Jul 2020 19:42:41 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Fri, 31 Jul 2020 19:42:34 +0800 From: Wang ShaoBo CC: , , , , , Subject: [PATCH v2 -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c Date: Fri, 31 Jul 2020 19:42:14 +0800 Message-ID: <20200731114214.25654-1-bobo.shaobowang@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Function jvmti_write_code called by compiled_method_load_cb may return error in using fwrite_unlocked, this failure should be captured and warned. Signed-off-by: Wang ShaoBo --- tools/perf/jvmti/jvmti_agent.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index 88108598d6e9..dfb6cb8564cb 100644 --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c @@ -363,7 +363,7 @@ jvmti_write_code(void *agent, char const *sym, struct jr_code_load rec; size_t sym_len; FILE *fp = agent; - int ret = -1; + int sret; /* don't care about 0 length function, no samples */ if (size == 0) @@ -400,17 +400,24 @@ jvmti_write_code(void *agent, char const *sym, */ rec.code_index = code_generation++; - ret = fwrite_unlocked(&rec, sizeof(rec), 1, fp); - fwrite_unlocked(sym, sym_len, 1, fp); + sret = fwrite_unlocked(&rec, sizeof(rec), 1, fp); + if (sret != 1) + goto error; + sret = fwrite_unlocked(sym, sym_len, 1, fp); + if (sret != 1) + goto error; - if (code) - fwrite_unlocked(code, size, 1, fp); + if (code) { + sret = fwrite_unlocked(code, size, 1, fp); + if (sret != 1) + goto error; + } funlockfile(fp); - - ret = 0; - - return ret; + return 0; +error: + funlockfile(fp); + return -1; } int -- 2.25.1