From patchwork Fri Sep 10 17:06:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12485639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E26D6C433F5 for ; Fri, 10 Sep 2021 17:08:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97EA8610C9 for ; Fri, 10 Sep 2021 17:08:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 97EA8610C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOk0Y-0002RL-Bv for qemu-devel@archiver.kernel.org; Fri, 10 Sep 2021 13:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOjzY-0000aL-0a for qemu-devel@nongnu.org; Fri, 10 Sep 2021 13:07:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOjzW-0004a1-H5 for qemu-devel@nongnu.org; Fri, 10 Sep 2021 13:07:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631293625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+J6grQHEVtN6t6ceYCiTjy1J8psdb3VCBa42DzLh0ro=; b=Wz1G1lUT4qZLfBQWVezrKm40Lsi5P04dx/4lLBRmE3/LoJ08b3o3/inkLbWdoKcz2td2+B BfbITM1wdqKMja4DIadEefgI5FsfgKtu55DJi5onSqWaRcyK8WvSNgvS3mx/ASDm0uHXcs oT0kvHkXGesVZVMFLK5oCMlBQlqLpW8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-Pz_zh2KQPVOFadhictixpQ-1; Fri, 10 Sep 2021 13:07:04 -0400 X-MC-Unique: Pz_zh2KQPVOFadhictixpQ-1 Received: by mail-wr1-f72.google.com with SMTP id t15-20020a5d42cf000000b001565f9c9ee8so761878wrr.2 for ; Fri, 10 Sep 2021 10:07:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+J6grQHEVtN6t6ceYCiTjy1J8psdb3VCBa42DzLh0ro=; b=6ksnvVNRA1cZ6zl4W3qDw1vZjl12cxiWYokP55qhndN/NhWzq5cWs0Jd0/rUobqkCF OtHFzfphe/ukifmbbXcfn8IMAnZmAXOBQfqgGNrB6X7v5B0soS7KeHF2ezF9IhEa6RvM Cc45dwh3sW9U1PnMTvnz9ZnFmwNqpSP++uPgxnW/1LJFIc0rutAA1qtM555YSBtdKfoI 4Wb2747K9Ll9UKKOvUhHodvqvVNwK2y7gX5of+vOiFFOfrPwiDXM7X1zn/uc8u3E/Pu7 ZxIXsvAoI7c++zoOmvhGeMFpgFNx99EyJYekWkWQC0/3/t9Lezvx/ptV7VKndVmooiub FHfQ== X-Gm-Message-State: AOAM530qpYpP1q6ZXM1IjbjvDx832f7ILQyciE7mtDeOjrgD1ChkE0pw QIzwhcgpEzarWAlKL7UpOHvNY3cqpC6WmgOH88HQfoedtCvJqP/PgNYhIppjNHrXEsuLoZNMynj ZDVlsttIBDdgLJndruv3v76OZMWocdxdZ54+WzFRpVaSaxol7e1w8/+qlNqIu1sIA X-Received: by 2002:adf:e10c:: with SMTP id t12mr11044275wrz.36.1631293622959; Fri, 10 Sep 2021 10:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLEuQvoH8Q4d1gl0AIR6gDpffsEipUhurj8eO/D6QvQQ3qUnATr9au9snwEJq1wsw2L1iVZA== X-Received: by 2002:adf:e10c:: with SMTP id t12mr11044239wrz.36.1631293622698; Fri, 10 Sep 2021 10:07:02 -0700 (PDT) Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id u16sm5233423wmc.41.2021.09.10.10.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 10:07:02 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] elf2dmp: Check curl_easy_setopt() return value Date: Fri, 10 Sep 2021 19:06:55 +0200 Message-Id: <20210910170656.366592-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910170656.366592-1-philmd@redhat.com> References: <20210910170656.366592-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Dau?= =?utf-8?q?d=C3=A9?= , Viktor Prutyanov Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Coverity points out that we aren't checking the return value from curl_easy_setopt(). Fixes: Coverity CID 1458895 Inspired-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Viktor Prutyanov Tested-by: Viktor Prutyanov --- Informal T-b tag on https://lore.kernel.org/qemu-devel/20210909004313.1dadb24e@192.168.1.7/ Tested-by: Viktor Prutyanov v1 from Peter: https://lore.kernel.org/qemu-devel/20210901143910.17112-2-peter.maydell@linaro.org/ --- contrib/elf2dmp/download.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c index d09e607431f..bd7650a7a27 100644 --- a/contrib/elf2dmp/download.c +++ b/contrib/elf2dmp/download.c @@ -25,21 +25,19 @@ int download_url(const char *name, const char *url) goto out_curl; } - curl_easy_setopt(curl, CURLOPT_URL, url); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); - - if (curl_easy_perform(curl) != CURLE_OK) { - err = 1; - fclose(file); + if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK + || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) != CURLE_OK + || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) != CURLE_OK + || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK + || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) != CURLE_OK + || curl_easy_perform(curl) != CURLE_OK) { unlink(name); - goto out_curl; + fclose(file); + err = 1; + } else { + err = fclose(file); } - err = fclose(file); - out_curl: curl_easy_cleanup(curl); From patchwork Fri Sep 10 17:06:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 12485641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54EE1C433F5 for ; Fri, 10 Sep 2021 17:08:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1FE8F611CB for ; Fri, 10 Sep 2021 17:08:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1FE8F611CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:41874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOk0g-0002o2-7u for qemu-devel@archiver.kernel.org; Fri, 10 Sep 2021 13:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOjzd-0000j5-Pr for qemu-devel@nongnu.org; Fri, 10 Sep 2021 13:07:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60988) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOjzc-0004fC-5M for qemu-devel@nongnu.org; Fri, 10 Sep 2021 13:07:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631293631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZqCkNbuM43KqzBbq91YsLm9a1aNQ2XjTVYVG98V6beo=; b=LUfZ86S9ojQi6nBd4mSikbDCM8uDI1wsHTi+xLVhvWjRl+c593nkbPgnQs5p+M3b8I7acP snc4Pa+jdGQzly0wQZR4Vf1sMsW3KpstG+lOnFDCoAcz6o7JUADHhrFoHnfTisY4WgOu5Z 0Pau84zHM6BbJ0E0y8R366r5Ol/Z1bY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-rXG9je3ONXaXp55gpWdGAw-1; Fri, 10 Sep 2021 13:07:10 -0400 X-MC-Unique: rXG9je3ONXaXp55gpWdGAw-1 Received: by mail-wm1-f71.google.com with SMTP id u14-20020a7bcb0e0000b0290248831d46e4so827325wmj.6 for ; Fri, 10 Sep 2021 10:07:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZqCkNbuM43KqzBbq91YsLm9a1aNQ2XjTVYVG98V6beo=; b=VIpVKqcUay147/sVJAJ0iYybgDFDH/++YoWEnqIKbyURu9P+8JDczaI4Yw2Zzaqtwv 0IJuhiT5DgEmPRjuWpEbw+E/VP86k4K4jGHu8kGYijlbGIVb+Kfi3p/SMmET98TLkaF/ 68vh1cMxDUFnhDbogV1mnBAu4Th9e2hiVsWV43K5XQXm8kPXu+KOCU7qnz6Y2m5cgaKM gybABiVhvWAvzN0+Uy2Yu9+XapLXQ4WIydKd29waxOgJqpTjKpc6d7B7880pwiy0gS4G cosm5ZcX9+cnHNFU+ZksaWKz33KHSiKV+HePB5duOLRNpL9QQeT+1bHmOL/rWcJZ4XEL 3Q9Q== X-Gm-Message-State: AOAM532AXDqFBynxGdJZ5za24idW5hQv4N0NfaICxKq4559QUg4VDlW0 hvUAC3pEkf2F1bEPGMjpQrUx84i+FzGaZ6kX/Kfqbs8tkV0HMgpKkJeHm6CSMuaqug9LPe/Ahfq 4Paygo+MmmR+QWke+raRB5UlpZoQtBMBJlvAMneEdkzo9Io1HWncMSY8d+lUiVj9L X-Received: by 2002:a1c:f315:: with SMTP id q21mr9762007wmq.76.1631293627597; Fri, 10 Sep 2021 10:07:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp5/JfK+/TzVHdCEfyaUtpwZx22vL4CKuHlqAkJL5PWlNiszGXnrUCo9+WuTknLmHLX2nZyw== X-Received: by 2002:a1c:f315:: with SMTP id q21mr9761974wmq.76.1631293627311; Fri, 10 Sep 2021 10:07:07 -0700 (PDT) Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id z1sm4789570wmi.34.2021.09.10.10.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 10:07:06 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] elf2dmp: Fail cleanly if PDB file specifies zero block_size Date: Fri, 10 Sep 2021 19:06:56 +0200 Message-Id: <20210910170656.366592-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210910170656.366592-1-philmd@redhat.com> References: <20210910170656.366592-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-Dau?= =?utf-8?q?d=C3=A9?= , Viktor Prutyanov Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Coverity points out that if the PDB file we're trying to read has a header specifying a block_size of zero then we will end up trying to divide by zero in pdb_ds_read_file(). Check for this and fail cleanly instead. Fixes: Coverity CID 1458869 Signed-off-by: Peter Maydell Reviewed-by: Viktor Prutyanov Message-Id: <20210901143910.17112-3-peter.maydell@linaro.org> Signed-off-by: Philippe Mathieu-Daudé Tested-by: Viktor Prutyanov --- Informal T-b tag on https://lore.kernel.org/qemu-devel/20210909004313.1dadb24e@192.168.1.7/ Tested-by: Viktor Prutyanov --- contrib/elf2dmp/pdb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index b3a65470680..adcfa7e154c 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -215,6 +215,10 @@ out_symbols: static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) { + if (hdr->block_size == 0) { + return 1; + } + memset(r->file_used, 0, sizeof(r->file_used)); r->ds.header = hdr; r->ds.toc = pdb_ds_read(hdr, (uint32_t *)((uint8_t *)hdr +