Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2047079ybh; Fri, 24 Jul 2020 03:08:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiig1XpMNOSmLd0rpaFece53fUX4wOWLUX3EASeCWUah677OEhMD6ZUmT7bvYRRT2wauWQ X-Received: by 2002:a17:907:41dc:: with SMTP id og20mr8758133ejb.183.1595585334149; Fri, 24 Jul 2020 03:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595585334; cv=none; d=google.com; s=arc-20160816; b=qtCmrB+y2hWnhMoPZFiDBsHDgzwDO/IhMynq+ivfunKnA1jP46EaKh5rQoeeg31Ccv jGHKixPUwhRxa4sb9qIXkaHu82aY0NVg2RMmP2iZjRd183xnX8CwQpeyM4FLB4eDyteN VoSJoZhb1BiOicXzgGFreYsu6Tdlh1KJ6W7Q1QaizBCM/qIrOo7O+/0vMTxyYIajk6+j AvhLs9M7p6kjbhHltBJKFBk6/3LMPDTCuw2N04BFpIWOTGf0sDAK4L06x/9LTj9xjJns ImZIGsDMzouPpuie6mmhVvHRfMH+79gkkVdY4aJ9DpR9MNxPCNcP6KeTdOOSJx1mBdGi +qLg== 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=E1j8mIGL3WBurZjNHudOY4RxxF6FEXaL6OME2lxUPKQ=; b=NMWU0srSaKHUXx/6EMx6AX15B197Pzeax1Tj9NWgKvaCBdjQZRPLUjLct4IEMTmiKx OGqAZB6bGwPfY5phH69hGhT0h6wSXoEjkyumjxeFZ66wQnb9c0qh+vJGwDY2swxgl76B 9CWFhECTtY+r8LeN1N0WirHnseTEXIxmbfgoHbqpqD7pfh3Pwdc2PBIqCCOJQBzob/UF BII/HcWGjbPqoeoL3gJmVtmMHi2yGNiZQGpoNqJy4K5Z2zXG0p9hCSVyJEpMlJnRvxcI 2hqBhwd7Zt+MqCNiplOCgFF0Nax5wRjk+7H0CLYSkzrAY4j32R8EJQ/r1yuKomHj5zwH G0uA== 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 z24si266319eja.705.2020.07.24.03.08.31; Fri, 24 Jul 2020 03:08:54 -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 S1727932AbgGXKHc (ORCPT + 99 others); Fri, 24 Jul 2020 06:07:32 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8272 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726114AbgGXKHc (ORCPT ); Fri, 24 Jul 2020 06:07:32 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 32FFDFAD88DD2DE5C59D; Fri, 24 Jul 2020 18:07:30 +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; Fri, 24 Jul 2020 18:07:23 +0800 From: Wang ShaoBo CC: , , , , , Subject: [PATCH -next] tools build: Check return value of fwrite_unlocked in jvmti_agent.c Date: Fri, 24 Jul 2020 18:07:06 +0800 Message-ID: <20200724100706.48330-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 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index 88108598d6e9..a1fe6aa16b6d 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 ret; /* don't care about 0 length function, no samples */ if (size == 0) @@ -401,16 +401,23 @@ 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); + if (ret) + goto error; + ret = fwrite_unlocked(sym, sym_len, 1, fp); + if (ret) + goto error; - if (code) - fwrite_unlocked(code, size, 1, fp); + if (code) { + ret = fwrite_unlocked(code, size, 1, fp); + if (ret) + goto error; + } funlockfile(fp); - - ret = 0; - - return ret; + return 0; +error: + funlockfile(fp); + return -1; } int -- 2.17.1