From patchwork Thu Sep 22 12:13:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 76767 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp8824qgf; Thu, 22 Sep 2016 05:41:14 -0700 (PDT) X-Received: by 10.55.138.67 with SMTP id m64mr1823531qkd.265.1474548074060; Thu, 22 Sep 2016 05:41:14 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 32si998490qtf.101.2016.09.22.05.41.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 22 Sep 2016 05:41:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn3JR-00089M-Hu for patch@linaro.org; Thu, 22 Sep 2016 08:41:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2uK-00005J-FG for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn2uE-0006aE-GC for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:15:16 -0400 Received: from mail-lf0-f42.google.com ([209.85.215.42]:36560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2uE-0006ZH-9R for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:15:10 -0400 Received: by mail-lf0-f42.google.com with SMTP id g62so65198358lfe.3 for ; Thu, 22 Sep 2016 05:15:10 -0700 (PDT) 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; bh=ibwAjpX3b/WWgSObHmvEJceIaSFznSIVYtW5FxJyPZw=; b=XvWeYqLvABn8x3eStLoIUnV4Ye9J86V0QlMFCDJfHjSZc0XR8LqTW2TOGb0WyUaRI2 rI4jJjrvCYYKUVjmvYO13CXM6aF3UVTnCC1LMtxPB5HuGZT+RcctLH33esS+lsHKMPcr 3p0aiwu6G3lYtzMEYNjr6qBszn6HZ7ENCoDW4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ibwAjpX3b/WWgSObHmvEJceIaSFznSIVYtW5FxJyPZw=; b=fGlOk0WhZK1qmrBCrV4aqHRSflTkxkhS+UOgXzNRMrbQ3McuxnbaNRcvh/Fg7PhaPa aN5aQcAvRP4IgTyUaG5WHRw6YNXMd0cXmJ/GRfg4aEXKEGyk/qOudegf/rP2tNEd/+I7 +RLQPen0G7eCIs807zE803PVF4VKykxnoeel0Zm2f1wjkAFEntbUYRP5eKrt9T+G8bVO 7qztA/pketBgtDOHk1173DI4D0UC/3HrE2xvAiNrp0erwYyF9hI3EG23J5h74K9Ah1fP fCqXZfXxukol4XYgpi6bbSafDQP7SYqFJ35ry7RnshLFtt+IDn8lwNTMHKg61MaERlqQ Bs0Q== X-Gm-Message-State: AE9vXwPGFN2JdFSlPMMauvyY8TDwghB77nHg5nrICef4RFgbXplJJCanQR+mqKVRtT/yU+Nw X-Received: by 10.25.27.139 with SMTP id b133mr610523lfb.157.1474546449473; Thu, 22 Sep 2016 05:14:09 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id u14sm294378lja.11.2016.09.22.05.14.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Sep 2016 05:14:08 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Thu, 22 Sep 2016 15:13:34 +0300 Message-Id: <0ef9ea290ed9319cb788ea40be06dd18b32ba05a.1474546244.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.42 Subject: [Qemu-devel] [PULL 14/26] linux-user: Use glib malloc functions in load_symbols() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell Switch to using the glib malloc functions in load_symbols(); this deals with a Coverity complaint about possible integer overflow calculating the allocation size with 'nsyms * sizeof(*syms)'. Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/elfload.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) -- 2.1.4 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0d07b85..3d751f8 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2111,19 +2111,19 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) found: /* Now know where the strtab and symtab are. Snarf them. */ - s = malloc(sizeof(*s)); + s = g_try_new(struct syminfo, 1); if (!s) { goto give_up; } i = shdr[str_idx].sh_size; - s->disas_strtab = strings = malloc(i); + s->disas_strtab = strings = g_try_malloc(i); if (!strings || pread(fd, strings, i, shdr[str_idx].sh_offset) != i) { goto give_up; } i = shdr[sym_idx].sh_size; - syms = malloc(i); + syms = g_try_malloc(i); if (!syms || pread(fd, syms, i, shdr[sym_idx].sh_offset) != i) { goto give_up; } @@ -2157,7 +2157,7 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) that we threw away. Whether or not this has any effect on the memory allocation depends on the malloc implementation and how many symbols we managed to discard. */ - new_syms = realloc(syms, nsyms * sizeof(*syms)); + new_syms = g_try_renew(struct elf_sym, syms, nsyms); if (new_syms == NULL) { goto give_up; } @@ -2178,9 +2178,9 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias) return; give_up: - free(s); - free(strings); - free(syms); + g_free(s); + g_free(strings); + g_free(syms); } int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)