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>
This commit is contained in:
parent
d0b3ab0a0f
commit
1937095588
3 changed files with 16 additions and 1 deletions
10
dtc-parser.y
10
dtc-parser.y
|
@ -410,7 +410,15 @@ integer_add:
|
||||||
|
|
||||||
integer_mul:
|
integer_mul:
|
||||||
integer_mul '*' integer_unary { $$ = $1 * $3; }
|
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_mul '%' integer_unary { $$ = $1 % $3; }
|
||||||
| integer_unary
|
| integer_unary
|
||||||
;
|
;
|
||||||
|
|
5
tests/division-by-zero.dts
Normal file
5
tests/division-by-zero.dts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
prop = < (1/0) >;
|
||||||
|
};
|
|
@ -289,6 +289,8 @@ libfdt_tests () {
|
||||||
run_test dtbs_equal_ordered embedded_nul.test.dtb embedded_nul_equiv.test.dtb
|
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_dtc_test -I dts -O dtb bad-size-cells.dts
|
||||||
|
|
||||||
|
run_wrap_error_test $DTC division-by-zero.dts
|
||||||
}
|
}
|
||||||
|
|
||||||
dtc_tests () {
|
dtc_tests () {
|
||||||
|
|
Loading…
Reference in a new issue