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: 508777 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp1510541jai; Fri, 10 Sep 2021 10:08:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDvZ6LcNhOz4l5BR7GACEpdoY9sOxrNLyEOLe46dvFU981fjamldtQbSAX3384YwFgGiF+ X-Received: by 2002:adf:c18d:: with SMTP id x13mr11135701wre.380.1631293680989; Fri, 10 Sep 2021 10:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631293680; cv=none; d=google.com; s=arc-20160816; b=cd6yQWQTnBEq3Pv9axtP8vYF/APPzjM8uhpcOGwVZEJfPQzM/9lMs83qJsXA86ldOx BNalC9IMldhH8pDHqjygsJXOR4kSfAs0+hnEm60ghMAgNbvJyo8uEXOLNqji0jHqK/5s tXbCY2K3WrPURX+VazvUVTUvIf5b3WwYe5LUrp6OjgWHKHKmX5YHwGVEV2I+WJQJQMaL 80U65bQo33cfuFvytz8mbrYtGJeBg4/5ZD4VdQYlogGTYhTkN2GLd+/zP0+IfqGUbWSn GsdF8ufwdNEeiULKgKmITkL3Rh/OTIOQe/ANkbRZlCkFq8zHB9vHGwyh9BZbFldQNKUi H2NQ== 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=ZqCkNbuM43KqzBbq91YsLm9a1aNQ2XjTVYVG98V6beo=; b=FLD1kP1AxLJi+SC5MfTIHiV9feSjIAAwcqhpqTvPzHUOn9dJ5fV1VRqG7msaUnmvvA UnpguhAkOzZrsXPP1HqWZdreqtoVJD1RKDiQK3E65Qn0r6MrjnWB8scZG5lzJzBPKbGD pXqETp1OacIs23HisklgSCLq/YseVI42bWeXdaTDHUtobz79E0+3K6XWXyvutFSPTW9K nbQY4x+Gw9RFiOZSLryZiwbJGpZEJjUTIZUytzeBucJZhrR/RFJt99kIRA+gl2nyUtjk IO5aWwuEvitm4NSu+g7K1iTfCvoSpHatprqHDd6YjLFVzos4/D0YdXK7MCXEjOradds2 uy7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=LUfZ86S9; 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 b11si6909545wrh.0.2021.09.10.10.08.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Sep 2021 10:08:00 -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=@redhat.com header.s=mimecast20190719 header.b=LUfZ86S9; 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]:38828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOk0O-0000nb-2N for patch@linaro.org; Fri, 10 Sep 2021 13:08:00 -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-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-D?= =?utf-8?b?YXVkw6k=?= , Viktor Prutyanov Errors-To: qemu-devel-bounces+patch=linaro.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é --- 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(+) -- 2.31.1 Tested-by: Viktor Prutyanov 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 +