devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jack Miller <jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] Fix crash with poorly defined #size-cells
Date: Wed, 29 Apr 2015 14:02:24 -0500	[thread overview]
Message-ID: <1430334144-26986-1-git-send-email-jack@codezen.org> (raw)

If you have a parent block with #size-cells improperly set to 0, and
then subsequently try to include a regs property in the child, dtc will
crash with SIGFPE while validating it. This patch fixes that crash,
instead printing the same invalid length warning that was causing it.

Test included.

Signed-off-by: Jack Miller <jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
---
 checks.c                 |  2 +-
 tests/bad-size-cells.dts | 12 ++++++++++++
 tests/run_tests.sh       |  2 ++
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 tests/bad-size-cells.dts

diff --git a/checks.c b/checks.c
index e81a8c7..0c03ac9 100644
--- a/checks.c
+++ b/checks.c
@@ -560,7 +560,7 @@ static void check_reg_format(struct check *c, struct node *dt,
 	size_cells = node_size_cells(node->parent);
 	entrylen = (addr_cells + size_cells) * sizeof(cell_t);
 
-	if ((prop->val.len % entrylen) != 0)
+	if (!entrylen || (prop->val.len % entrylen) != 0)
 		FAIL(c, "\"reg\" property in %s has invalid length (%d bytes) "
 		     "(#address-cells == %d, #size-cells == %d)",
 		     node->fullpath, prop->val.len, addr_cells, size_cells);
diff --git a/tests/bad-size-cells.dts b/tests/bad-size-cells.dts
new file mode 100644
index 0000000..515c0cc
--- /dev/null
+++ b/tests/bad-size-cells.dts
@@ -0,0 +1,12 @@
+/dts-v1/;
+
+/ {
+	mangled {
+		#address-cells = <0x0>;
+		#size-cells = <0x0>;
+
+		valid {
+            reg = <0x0 0x4000000>;
+        };
+    };
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 5331856..c870432 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -279,6 +279,8 @@ libfdt_tests () {
     run_dtc_test -I dts -O dtb -o embedded_nul.test.dtb embedded_nul.dts
     run_dtc_test -I dts -O dtb -o embedded_nul_equiv.test.dtb embedded_nul_equiv.dts
     run_test dtbs_equal_ordered embedded_nul.test.dtb embedded_nul_equiv.test.dtb
+
+    run_dtc_test -I dts -O dtb bad-size-cells.dts
 }
 
 dtc_tests () {
-- 
2.3.6

             reply	other threads:[~2015-04-29 19:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-29 19:02 Jack Miller [this message]
     [not found] ` <1430334144-26986-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
2015-04-30  0:56   ` [PATCH] Fix crash with poorly defined #size-cells David Gibson

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=1430334144-26986-1-git-send-email-jack@codezen.org \
    --to=jack-jzyo8ziazd9afugrpc6u6w@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.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).