Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1703163pxa; Sun, 2 Aug 2020 17:58:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHJmc//G5XYdtt+nOCdXH6iJcYjocQz1pv9jmgUMWKn1LYUVKuixYFUcn+QkYlxEG/aoIA X-Received: by 2002:a17:906:7f0b:: with SMTP id d11mr15172638ejr.116.1596416320503; Sun, 02 Aug 2020 17:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596416320; cv=none; d=google.com; s=arc-20160816; b=ALQ3BsGeVNyy5vts/9MycaMYtrvL9QmOl4qntZA3YR1tvTN0iQhDn73nNMRr0+5QcA 8NRk5jrQEpcZki0oXh19aIKJIouMt9hqzLFynn1JJzwQByTjahTAObAiH6VHZxcgarvf Tb6YxnA3anhTGawBFAoqcdsmOBj7G44Yw/+zgsmRtkVt29vv6XB2+Kob8wIVzjPJ8qgd pXvov1nowtvBnmSHRmrXKbl7CndTBJ3mJ3zFXhA4AxYIJVIM0p8iqBdSVl0pM7ARYjhT QrQAD5uhkHuIqr6stFRe7e1UOzWwhVef/cH+wDTNbUuGBQj3H+pH4U16TQJv2DViDUrx 4+yg== 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=mbz1REpuEcHmGmtlLkx55ClVA4KtE34ABqb0TjpoUT2DXwrhGtTdQC5BR3qC3MkEgq 4vahMWPM8RxyEEydjfvLcb0hBwwbepz9Xx2QsEwG+NU4miAOcGwz8LWA7fOm0lQLnl5w 6eOem7wlhJ9qvLCttV2r48H/1/7Zm6ltRhRKx+PZhSV94dpqOqJVPTCNSj9fJbfKTRfe KGQj3zq0cNc36K71Ai9Kvf02so0RPZRHG9mBMi3g1x3MUT1eHSa8UTcuz/OMuXvaY6c7 S+oCFniJPA48vEEV3kgmmTnNV45ytqduek+uX694w2HY38D1UFIGv79DhkjHU8nsl+2v HEUg== 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 i17si8983748ejr.275.2020.08.02.17.58.18; Sun, 02 Aug 2020 17:58:40 -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 S1726511AbgHCA5J (ORCPT + 99 others); Sun, 2 Aug 2020 20:57:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:9315 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725881AbgHCA5J (ORCPT ); Sun, 2 Aug 2020 20:57:09 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 11092ABB9F2F3570F786; Mon, 3 Aug 2020 08:57:06 +0800 (CST) Received: from huawei.com (10.175.124.27) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Mon, 3 Aug 2020 08:56:58 +0800 From: Wang ShaoBo CC: , , , , , Subject: [PATCH v2 -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c Date: Mon, 3 Aug 2020 08:56:29 +0800 Message-ID: <20200803005629.40651-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