Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp178095imd; Wed, 31 Oct 2018 16:53:49 -0700 (PDT) X-Google-Smtp-Source: AJdET5fqOw/owc8gPt+jIXyw6lLRwo/I36JvytNU9iS2OeUldsiXJ1J1gQHKYZbso8uPl2Pyy5D1 X-Received: by 2002:a62:42dc:: with SMTP id h89-v6mr5602855pfd.0.1541030029598; Wed, 31 Oct 2018 16:53:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030029; cv=none; d=google.com; s=arc-20160816; b=xCbRyJL2CvYTqQkIfaQ51m2S5zRyZ+bjoGpFk6P/iSbDVjVV8tJ4nBKujv2iybjEa4 tNoTzOdJuszTf7L9k0d9TYA6MNz70lhU/yFLuS/0LBvdRkjoqRh6uK3qJsec/lJU7lG3 gmYE1e5ZNVJkaDqgkrNXSsXoBhyyb0NxAzNYJYcfKSnHjMpC/pJNda2M25aJGrWaXJpg z8AwBuUh03HcgW4nPQEXl39+6ZmUYcOkgBEXTt1/vU8XrLdHH5FCOZBcVnlWyAM4YeRJ AszZS/yS95KVbOhpt+Bip2JR3UYQQLbb+zALsIuRf40XCwArjwsZO6oIc0Q5y7pDSG5W cfZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=y8EJ+jXYVe57k2yPL7vrY6wobTM6pZ/GX+s6PcM9FRs=; b=pffzJlQdDJBEoaJcVS+GcLkEum+P1betMy8F32xVyyFbA6nriVeceaq00+D6Ftqa7I dZPLsC0s6ecMtdJb6QiBui//lodIjNmhOXG/sa6X0slkys8eG5AAW8t4QBiM3ZaPQs1w Tdw7/Igv5c4KloJDV8IDX9DDM6BpBpVrN/j1qqfzdJTCv6GKXAGkgyx2pjs08LPZwuf8 j+xQ7pTkmjhhb/xg0PcZvwp5r/JGo1sYmU3b5zGZNz976702UvE9d60elY12/oJatGj4 yTAkng3o6pdNfnSvpyvH0WkGVqhGsRHHCK+EVTkD8Ry5BjLU3lUa3Of9bhYtr90lNvBi nqTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tn3EukAH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7-v6si27530593pln.175.2018.10.31.16.53.34; Wed, 31 Oct 2018 16:53:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tn3EukAH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727696AbeKAIGO (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:52974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbeKAIGM (ORCPT ); Thu, 1 Nov 2018 04:06:12 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 76E2520830; Wed, 31 Oct 2018 23:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027162; bh=FkjLfiO/5jDWGMgIVUu4SwbNGXQ/kS/nJCgbZurLHBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tn3EukAHhDa7Sj0NjxkGn32pp2Oe8UeCXO7mugugZoC2QhyUAHoIug4kJf0Czy9Hf J+WMBhhrCVafCozRU+hxGFgRBJvNRilHCKrbRBUV085FxnIZW9t15uvFr40mTHnhSC 4DVMzWCtSm4Tp0sekjxV0dHRTlwfHlzkOwqh9dS0= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sanskriti Sharma , Joe Lawrence , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 4.19 021/146] perf strbuf: Match va_{add,copy} with va_end Date: Wed, 31 Oct 2018 19:03:36 -0400 Message-Id: <20181031230541.28822-21-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sanskriti Sharma [ Upstream commit ce49d8436cffa9b7a6a5f110879d53e89dbc6746 ] Ensure that all code paths in strbuf_addv() call va_end() on the ap_saved copy that was made. Fixes the following coverity complaint: Error: VARARGS (CWE-237): [#def683] tools/perf/util/strbuf.c:106: missing_va_end: va_end was not called for "ap_saved". Signed-off-by: Sanskriti Sharma Reviewed-by: Jiri Olsa Cc: Joe Lawrence Link: http://lkml.kernel.org/r/1538490554-8161-2-git-send-email-sansharm@redhat.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/strbuf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c index 3d1cf5bf7f18..9005fbe0780e 100644 --- a/tools/perf/util/strbuf.c +++ b/tools/perf/util/strbuf.c @@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap) va_copy(ap_saved, ap); len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); - if (len < 0) + if (len < 0) { + va_end(ap_saved); return len; + } if (len > strbuf_avail(sb)) { ret = strbuf_grow(sb, len); - if (ret) + if (ret) { + va_end(ap_saved); return ret; + } len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); va_end(ap_saved); if (len > strbuf_avail(sb)) { pr_debug("this should not happen, your vsnprintf is broken"); + va_end(ap_saved); return -EINVAL; } } + va_end(ap_saved); return strbuf_setlen(sb, sb->len + len); } -- 2.17.1