qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: qemu-devel@nongnu.org
Cc: Michael Davidsaver <mdavidsaver@gmail.com>,
	linux-renesas-soc@vger.kernel.org,
	Wolfram Sang <wsa+renesas@sang-engineering.com>
Subject: [Qemu-devel] [PATCH 2/3] nvram: at24c: prevent segfault by checking "rom-size"
Date: Mon, 12 Mar 2018 22:42:29 +0100	[thread overview]
Message-ID: <20180312214230.17561-3-wsa+renesas@sang-engineering.com> (raw)
In-Reply-To: <20180312214230.17561-1-wsa+renesas@sang-engineering.com>

The value for "rom-size" is used as a divisor, so it must not be 0 or it
will segfault. A size of 0 wouldn't make sense as well.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 hw/nvram/eeprom_at24c.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 8507516b7e..d82710e1df 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -120,6 +120,11 @@ int at24c_eeprom_init(I2CSlave *i2c)
 {
     EEPROMState *ee = AT24C_EE(i2c);
 
+    if (!ee->rsize) {
+        ERR("rom-size not allowed to be 0\n");
+        exit(1);
+    }
+
     ee->mem = g_malloc0(ee->rsize);
 
     if (ee->blk) {
-- 
2.11.0

  parent reply	other threads:[~2018-03-12 21:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12 21:42 [Qemu-devel] [PATCH 0/3] nvram: at24c: fix problems related to "rom-size" Wolfram Sang
2018-03-12 21:42 ` [Qemu-devel] [PATCH 1/3] nvram: at24c: remove doubled prefix for ERR Wolfram Sang
2018-03-13 10:57   ` Philippe Mathieu-Daudé
2018-03-13 20:10     ` Wolfram Sang
2018-03-12 21:42 ` Wolfram Sang [this message]
2018-03-13 10:59   ` [Qemu-devel] [PATCH 2/3] nvram: at24c: prevent segfault by checking "rom-size" Philippe Mathieu-Daudé
2018-03-12 21:42 ` [Qemu-devel] [PATCH 3/3] nvram: at24c: use a sane default for "rom-size" Wolfram Sang
2018-03-13 10:53   ` Philippe Mathieu-Daudé
2018-03-13 20:16     ` Wolfram Sang
2018-03-18 23:50       ` Philippe Mathieu-Daudé
2018-03-19  8:33         ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180312214230.17561-3-wsa+renesas@sang-engineering.com \
    --to=wsa+renesas@sang-engineering.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mdavidsaver@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).