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: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	linux-renesas-soc@vger.kernel.org,
	"Wolfram Sang" <wsa+renesas@sang-engineering.com>
Subject: [Qemu-devel] [PATCH v3 1/3] nvram: at24c: prevent segfault by checking "rom-size"
Date: Tue, 20 Mar 2018 17:18:48 +0100	[thread overview]
Message-ID: <20180320161850.2104-2-wsa+renesas@sang-engineering.com> (raw)
In-Reply-To: <20180320161850.2104-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 anyhow.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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 22183f5360..ccf78b25e4 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -121,6 +121,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

  reply	other threads:[~2018-03-20 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 16:18 [Qemu-devel] [PATCH v3 0/3] nvram: at24c: fix problems related to "rom-size" Wolfram Sang
2018-03-20 16:18 ` Wolfram Sang [this message]
2018-03-20 16:18 ` [Qemu-devel] [PATCH v3 2/3] nvram: at24c: use a sane default for "rom-size" Wolfram Sang
2018-03-20 16:18 ` [Qemu-devel] [PATCH v3 3/3] nvram: at24c: use standard error reporting Wolfram Sang
2018-04-08  7:39 ` [Qemu-devel] [PATCH v3 0/3] nvram: at24c: fix problems related to "rom-size" 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=20180320161850.2104-2-wsa+renesas@sang-engineering.com \
    --to=wsa+renesas@sang-engineering.com \
    --cc=f4bug@amsat.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --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).