summaryrefslogtreecommitdiff
path: root/dtc-parser.y
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2016-01-03 22:27:32 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2016-01-03 22:27:32 +1100
commit19370955884ff0c49328956227c302225f4a014b (patch)
tree744f639f9ff5feae8cd8d27df1201e3fbd65c251 /dtc-parser.y
parentd0b3ab0a0f46ac929b4713da46f7fdcd893dd3bd (diff)
downloaddevice-tree-compiler-19370955884ff0c49328956227c302225f4a014b.tar.gz
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@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-parser.y')
-rw-r--r--dtc-parser.y10
1 files changed, 9 insertions, 1 deletions
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
;