From patchwork Tue Sep 28 12:51:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 514791 Delivered-To: patch@linaro.org Received: by 2002:a17:906:f46:0:0:0:0 with SMTP id h6csp4957590ejj; Tue, 28 Sep 2021 06:26:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9LsTbK1lULb2A40XYdDNu9dcDPpR013su/6OQRzFvO8/Q4ppcS8zSGFSZZ8irZ0i5RoVu X-Received: by 2002:a05:6102:48f:: with SMTP id n15mr1716774vsa.51.1632835562426; Tue, 28 Sep 2021 06:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632835562; cv=none; d=google.com; s=arc-20160816; b=x96yhVyzEbWzvRqy9YnQxxaFXx2MT5NlT7OrPo1BOxBd4bJvF31Pmn9M7I/mvhxx+t y2H99s3MKnYKSoT6+H9YP7oA/rRB4GWWXBwbiKPBgYt1s7KSTyGRVY2w7mHozfQFqlKw XZr7lBIzhF04KuepmwOUb2FOvNK6dMWwGriWu2i09/dbZorJajKTuJcfoNVVfRAelQbt Y4QfJG+OW/vu8CncBefvgZBKiNUMEkIKsnB1u6Bsa2mR8dJZCCWRk5riJiFZf6zgfRtA aj9fzCUk0C5zC/P/rhbI+f3CRH+4epaOlK0wBUUQh9gUZGwDc7olD+XaX2S85uAEnWlV G0rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hagtKSKeymEdKzgkRVDA/CGvBVgxGAcG0lg165ITsKM=; b=tL6pAOLRD6WEalWF+DSZ7D2A29WVwqsRRX2stlZ5+UJHGuFZS4fYZSbMoEbDhxf/e3 J+WtF3rZmrrqAOG+qCI2PlbC1fMAhpQVll7oibmbtY20DKrg/MwMHsqUPYG+mcz7xoux 0E1UM+LgKelwdZc8NSqofkAPz01ORF63ZCHoUZ0QKmZgair6NduvcLo2vBPbfeFt3dpC /20pf992v2TsXRAu57dCgWeEG6eb7WVEK5/ukzRl0SuT9u3iBmpvHIAYshTbA79qGuIY 3O3OKWlRht/gOGiNGrL0Fk4XydLekHlcvo7YDU2iKbrYkIRknxPWiu2dqW9KXriKDctb OqiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=Ebb3lRNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a4si144358vsn.265.2021.09.28.06.26.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Sep 2021 06:26:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=Ebb3lRNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:44572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVD7R-0001ma-3C for patch@linaro.org; Tue, 28 Sep 2021 09:26:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVCaM-0006gs-De for qemu-devel@nongnu.org; Tue, 28 Sep 2021 08:51:51 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:44890) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mVCaL-0001Yf-01 for qemu-devel@nongnu.org; Tue, 28 Sep 2021 08:51:50 -0400 Received: by mail-ed1-x535.google.com with SMTP id v18so47488346edc.11 for ; Tue, 28 Sep 2021 05:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hagtKSKeymEdKzgkRVDA/CGvBVgxGAcG0lg165ITsKM=; b=Ebb3lRNs/9hMdZ171UUJt0/7ti+KPSwu4BSU7jxoyK3gDV19UBqeqRKBe8AiZzpRjY gzwYRzxq1P/L6uWYmDL2K/rye7cRAq1E4gmNXnvJTuuVLr5sEG6FvXX3cns517eFTJfp RsXONxsgcibDpxZV+IJgPRbms3DXNuUSvJYgksuSWolKh3eIFgegdXLL9B5M+UZTP18Z kSUytmiyKjuWZ1xo/UEEWz6RYZZ3CXsbvV02pm8x60eqS0BepwZPerM3pxR63SpUTKXC 0HcttW9+gaWmncXZZoxOfiAkBig7zJjyTvLSAbxNC7tFgP4AW4/mejXJxjV941RPb+G6 cnDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hagtKSKeymEdKzgkRVDA/CGvBVgxGAcG0lg165ITsKM=; b=49b+iigKaJ6g1lm4Aukjf3aqkUIWKU67mJBBfc20UP+kmEUGQm/krzUH422BhOFZIF RCs1SDrKRbf2eedztIY5WQg0FvGfBLlSGRgWWKCZLR1hOqwnr0a3IOOuQepeDYpzfrRb hXOij4iatVwHhlgp65CBO/O/LoxI0hJrjfZn8hkCwrTfkaH1B+ccaN9/FrNM/usWSW7D LGJTmuB3lCnmuoaelmI6DBNxKxF4f60CUMipufTjB8lpi9HrxG/cnf/tBJcdRq/P9YDa aisG9Hf13/c3kCGpoC3DU/tmcwHh9sI2lf04JNeX5QVUP2x4cihM+yAmm3B/YIpD1tJC 9Dfg== X-Gm-Message-State: AOAM532bBe4UUDWedacgEx/bE5izEnaq64isy5fBIDNfihwEg6GM/Mnm XUALJovv9wo1Wqk2cCT8DhR2tKyEV5Q= X-Received: by 2002:a17:907:960f:: with SMTP id gb15mr1742004ejc.460.1632833501069; Tue, 28 Sep 2021 05:51:41 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id p24sm12641685edq.27.2021.09.28.05.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Sep 2021 05:51:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/33] target/i386: Fix memory leak in sev_read_file_base64() Date: Tue, 28 Sep 2021 14:51:12 +0200 Message-Id: <20210928125116.183620-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210928125116.183620-1-pbonzini@redhat.com> References: <20210928125116.183620-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x535.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-D?= =?utf-8?b?YXVkw6k=?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell In sev_read_file_base64() we call g_file_get_contents(), which allocates memory for the file contents. We then base64-decode the contents (which allocates another buffer for the decoded data), but forgot to free the memory for the original file data. Use g_autofree to ensure that the file data is freed. Fixes: Coverity CID 1459997 Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210820165650.2839-1-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- target/i386/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.31.1 diff --git a/target/i386/sev.c b/target/i386/sev.c index 0b2c8f594a..fa7210473a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -565,7 +565,7 @@ static int sev_read_file_base64(const char *filename, guchar **data, gsize *len) { gsize sz; - gchar *base64; + g_autofree gchar *base64 = NULL; GError *error = NULL; if (!g_file_get_contents(filename, &base64, &sz, &error)) {