From nobody Mon Feb 9 18:43:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1585734549; cv=none; d=zohomail.com; s=zohoarc; b=MiSt9y7C0jEfDfCkHv38B+x7sXNGYk/2Qnv4RI7Z97qQaTChgKwHX/2qBpHr65/JgpG4+hqZW7QBckbQOMbGjRmGKITDbMYhIs6sXXaI9iyhTe3hANm/LHBDp/+eQPVsaHTbVp/N7VDjCYgMjwqF/VRkK/a+ifWsA771owDMj4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585734549; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=ebnvwcb+1d50UPGueuKNcyqoLVx1Wec349l+z6s8jWDhT5VTLJ3FV8+ThVTCcRjCE+e7DFPT2IDh2aCnjB6n4Nf91VLshnUP5R80g0gXLCXtvSWrvhsQMHWPZFL1FBm0S+wfxjl9E5itY4vFuKhmSdrIBpUD+a9DC2I6mCbxfDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585734549398473.217863696683; Wed, 1 Apr 2020 02:49:09 -0700 (PDT) Received: from localhost ([::1]:57206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZzf-0005lT-D0 for importer@patchew.org; Wed, 01 Apr 2020 05:49:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38387) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyf-0004BJ-BF for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZye-000296-Ep for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:05 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:45978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZye-00028a-9G for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:04 -0400 Received: by mail-wr1-x444.google.com with SMTP id t7so29716404wrw.12 for ; Wed, 01 Apr 2020 02:48:04 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 9sm1926646wmm.6.2020.04.01.02.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:00 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E86F91FF87; Wed, 1 Apr 2020 10:47:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=LVtRNlmkf0SEwI6n3XILfZ5dEar6Zo/Wcgi6qnaCoi1I15MiGFbqSvCHsrv9PS3i1o ZMiAD67aotCYrzK/mZo5ttz70YvCuuDsocbEYl8SaXnBiDacY4z1kIdbGfhJF2Oud3U/ bNDIBt+ThGflldG5q3jWmGwCUq87h2Fg3D3wtQtE2RQdNfCPFSMcSXQkJulzKRT51EZu 31JXdpj+q/zsaPQbi1wlJOzgtB5hRwAdwaCf4ml64J0VSeTS8ARVn7qqrz5txk8zcPx6 1WW0NLaBO55JlFCDwJzC0C56/qfyc49QPJ+E65a3cXu8xA5TuaEj7KniqwPuxZuCoIt+ cFZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=Ct8B7oAoujH9cFYFZdan5M8QYLOVhX6/xaEE1expbTL7xEOHGY3R775T1nXDY8cutE HzzffU2TEuxhSOVYXvN6dtw/fbbCdPiwF0x25Hbh772DIEDMAWkA87POjf+Wc6WEpluN qGshfYffhTsP3gHdbEH5GrX/JDeLDTaP3MxWSbwZWtCh4kCND9lx/UFUgj4HzEXGskt6 +dH+XgoPtrLK1aLvQWXdmLjAdM+7JrynCCoiYMf3vxy8mPkOz6CKuLDGShHDyqMac+84 tioFYHBnGrj9jTQ9Uk/BdI+q0b4gCSGULso6+Lj//78M1f69n+L5KecvFzuePLaNBwUM M6Bw== X-Gm-Message-State: ANhLgQ3MrymAgA8LVTrmdbKZWeZkZ5/DEOlLhqZ2QksHMW25gA5oarvG fPCLUUqZo+novFi9resu+whQyg== X-Google-Smtp-Source: ADFU+vsr7EyfLQyeJzCaT+WrNl2x1XNaklo5gCYZfKRAM9VLGJbhHttSoMl3sjscGKELvUyjEgtMcw== X-Received: by 2002:adf:b6a5:: with SMTP id j37mr25065764wre.412.1585734483166; Wed, 01 Apr 2020 02:48:03 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] elf-ops: bail out if we have no function symbols Date: Wed, 1 Apr 2020 10:47:50 +0100 Message-Id: <20200401094759.5835-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) It's perfectly possible to have no function symbols in your elf file and if we do the undefined behaviour sanitizer rightly complains about us passing NULL to qsort. Check nsyms before we go ahead. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- include/hw/elf_ops.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index a1411bfcab6..b5d4074d1e3 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -170,8 +170,13 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr,= int fd, int must_swab, } i++; } - syms =3D g_realloc(syms, nsyms * sizeof(*syms)); =20 + /* check we have symbols left */ + if (nsyms =3D=3D 0) { + goto fail; + } + + syms =3D g_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); for (i =3D 0; i < nsyms - 1; i++) { if (syms[i].st_size =3D=3D 0) { --=20 2.20.1