From nobody Sun May 5 11:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631293626; cv=none; d=zohomail.com; s=zohoarc; b=B3Ha/7cIIRWwzEC1dcTd88K43QhCmk8Rw+OWZjRNLQ/ZDHmJn8FaYqwWPFOCW60Ta50ajX404gOFzKbKsWhzyu2HtPqZvCV2aLt2GMGcgLPGpM4JMRJvGW48+bq278QlM/95U4kmZfqV6env43TPMt/Bp2NHO/nfa5PKqeRSDw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631293626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=+J6grQHEVtN6t6ceYCiTjy1J8psdb3VCBa42DzLh0ro=; b=ek4KceD11rCi4oWHE2xxiaPjqm8ynWgwvPxCgSnlS+0uC4qsYSwVsFstLt83XMQmO0JtNW8dnM3Q2WxpTTDqsUNiXTI5NtIiTiYSwgG/p7bV7Mo9emj/Llnm3vqG7OU0+58L4t+GR/uozwK8N4jiq4nMNbUCG113CO5EXSRvKLk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1631293626701401.90303280140006; Fri, 10 Sep 2021 10:07:06 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-0WqUV4CcOgiwbf3s9wUcxw-1; Fri, 10 Sep 2021 13:07:04 -0400 Received: by mail-wm1-f70.google.com with SMTP id m16-20020a7bca50000000b002ee5287d4bfso827028wml.7 for ; Fri, 10 Sep 2021 10:07:04 -0700 (PDT) Return-Path: Return-Path: 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) 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= X-MC-Unique: 0WqUV4CcOgiwbf3s9wUcxw-1 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=E6DlfRL8W1RlOtwwbq6fVUiYGRYG8ZdpTgmKP0vkRM//7Qhgg4Okj2WQ5g4MMgeO58 qZADN/BfG96tgxyJYuQXCBB3Rfo5O4XsMVaD5tmaXQu9XPphDi+v03MyMKT69pDQlZl5 c/8wjPK6oe9dAKX9EGS06u00sGh4MACgRLBDfhmWXmkuAgE2+VaPVNkAaQnOpTQ0u1wB gQE4OWJXpuJKTOecANR3G5/63fIZ26co/zIIT9Ak9bfr7pCGvBMlZSKAphj+XkGAj8Sk vg1BqTgkYweyFeXgoO3oG/Z9DMvzWR5CpVovMet6uHivCkQjGRepzoSD02IA/yZbPf47 B5ig== X-Gm-Message-State: AOAM532hnQfBAaA3Cp6m9MQM3SHontFcXN+9okOgMCSqq03vGPUtrLCS j78ZkOfp1bqtUutQHAUKSCEg29Afi01YFWbvlJTslmpQ1E3LR7xo/PMU5zxBbBoFE1o5GWs5YeT TAXZ4QzVQESK8Uw== X-Received: by 2002:adf:e10c:: with SMTP id t12mr11044270wrz.36.1631293622920; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Viktor Prutyanov , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631293627256100001 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=C3=A9 Reviewed-by: Viktor Prutyanov Tested-by tag, so I haven't included it in the patches. 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@lin= aro.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; } =20 - 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) !=3D CURLE_OK) { - err =3D 1; - fclose(file); + if (curl_easy_setopt(curl, CURLOPT_URL, url) !=3D CURLE_OK + || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) !=3D CU= RLE_OK + || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) !=3D CURLE_= OK + || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) !=3D CURL= E_OK + || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) !=3D CURLE_OK + || curl_easy_perform(curl) !=3D CURLE_OK) { unlink(name); - goto out_curl; + fclose(file); + err =3D 1; + } else { + err =3D fclose(file); } =20 - err =3D fclose(file); - out_curl: curl_easy_cleanup(curl); =20 --=20 2.31.1 From nobody Sun May 5 11:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1631293631; cv=none; d=zohomail.com; s=zohoarc; b=ZsXOYm+yCsAbuuj5aABagWfVIUcPUmFQULnlNiYsEDAgpOK6WROaLDhYGbwPWxAOwDb9GLX1PIg5GuO45HpJNVf2OUHo7e0KM5VW0d3Cb9DahyVilozfM2mlW0W/wlhLnaY+IRJCTPpSOKK0Ac0TemLQWlAq5gEPLVMy/Ff/1Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1631293631; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ZqCkNbuM43KqzBbq91YsLm9a1aNQ2XjTVYVG98V6beo=; b=OMxrAMsf9RY6FrjzNkd2ZMZVk1DdvaGWwtyKaqgWtWlQc+3+7bImvLrastMV6H77+Qm1rF0CJWzzGoHVSybANSMi+/N2co/bMogfDkJ2uuhjspL1oZWw0x6s0C1emjRFDUSU98TmgE9Xj3fmL8u6ghNnworkptWi+9+lpytU8TA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1631293631511383.9306320354374; Fri, 10 Sep 2021 10:07:11 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-7nDE0RiCN-ixl4XoTuLFRQ-1; Fri, 10 Sep 2021 13:07:09 -0400 Received: by mail-wm1-f70.google.com with SMTP id m22-20020a7bcb96000000b002f7b840d9dcso834182wmi.1 for ; Fri, 10 Sep 2021 10:07:08 -0700 (PDT) Return-Path: Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631293630; 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=U72k1kPGPfofDIPQERLm83t06Cc2b3+xMV2uKhgW3cirilSowgtQ4MP7h/WJkK3CHEseZL KApkBSwVLmv/EtUqlV9lZRUC/Ob9+wwLqlLXcck56rOv/UrXdLhK9dk98osJzHwj6x6uMl 8HsrsF0SbaySvwGVuW0zH0lgzA8KARI= X-MC-Unique: 7nDE0RiCN-ixl4XoTuLFRQ-1 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=lqFrb9wYgRQ1wMyZv/hhPH/YNlnGsFn522orh0OmtEk+X/oWspAdhUe0ijRN61WO9m 3zDryBuk1Dd9txG6OfWE9FIO1NU9ihy+kzNNSCAWrkCky4soDDyQZdkTGpzDzll7sdKc ZhHKVzm9GevMYE1WsbFBA1Czo3S3Xnr46FC8cm0IBYHsdW+VSYdze7frN2m29JS7WDQd vyNQ3H7jlmHPId0H8s6tu4cZ6BIqv6pGki71TNM5klD4GE/uNcBk67EJZkky9vb4cpb9 T+QhUzWXT3C944xxBy11uZGDIjFvcZlRAJFV9pd7RbHQjcFS4HTjP6wthT8pAzHSxfeR CdBA== X-Gm-Message-State: AOAM530/YOzQqZmG3IwPoWRkHrE7D3teXQVSRsItPj4rjct6U7YUnKX3 wbst4qHPSDpSHvQznCVj0/fSDYZrkg83nBwb+nLbfMNLRAd0ca8MZciitsPVWv1fBer6hBeAdIH QCy6se0bDwkfhdA== X-Received: by 2002:a1c:f315:: with SMTP id q21mr9762001wmq.76.1631293627573; 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) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Viktor Prutyanov , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1631293633704100001 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=C3=A9 Tested-by tag, so I haven't included it in the patches. 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: =20 static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) { + if (hdr->block_size =3D=3D 0) { + return 1; + } + memset(r->file_used, 0, sizeof(r->file_used)); r->ds.header =3D hdr; r->ds.toc =3D pdb_ds_read(hdr, (uint32_t *)((uint8_t *)hdr + --=20 2.31.1