[Crosstoolchain-logs] [device-tree-compiler] 168/198: Prevent crash on division by zero

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:07:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.4.x
in repository device-tree-compiler.

commit 19370955884ff0c49328956227c302225f4a014b
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Sun Jan 3 22:27:32 2016 +1100

    Prevent crash on division by zero
    
    Currently, attempting to divide by zero in an integer expression in a dts
    file will cause dtc to crash with a division by zero (SIGFPE).
    
    This patch corrects this to properly detect this case and raise an error.
    
    Reported-by: Anton Blanchard <anton at samba.org>
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 dtc-parser.y               | 10 +++++++++-
 tests/division-by-zero.dts |  5 +++++
 tests/run_tests.sh         |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index 5a897e3..00d4dbb 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -410,7 +410,15 @@ integer_add:
 
 integer_mul:
 	  integer_mul '*' integer_unary { $$ = $1 * $3; }
-	| integer_mul '/' integer_unary { $$ = $1 / $3; }
+	| integer_mul '/' integer_unary
+		{
+			if ($3 != 0) {
+				$$ = $1 / $3;
+			} else {
+				ERROR(&@$, "Division by zero");
+				$$ = 0;
+			}
+		}
 	| integer_mul '%' integer_unary { $$ = $1 % $3; }
 	| integer_unary
 	;
diff --git a/tests/division-by-zero.dts b/tests/division-by-zero.dts
new file mode 100644
index 0000000..d26fc27
--- /dev/null
+++ b/tests/division-by-zero.dts
@@ -0,0 +1,5 @@
+/dts-v1/;
+
+/ {
+	prop = < (1/0) >;
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 1063d1e..3d6a230 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -289,6 +289,8 @@ libfdt_tests () {
     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
+
+    run_wrap_error_test $DTC division-by-zero.dts
 }
 
 dtc_tests () {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list