summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlina Moravcova Varekova <pmoravco@redhat.com>2019-09-18 13:23:45 +0300
committerPanu Matilainen <pmatilai@redhat.com>2019-11-18 12:46:29 +0200
commit934cf83adf86ef8ee3f3e08c7a666bcf4436f0c8 (patch)
treeaf42cc2ac8c85e86bbb3277b4d509904be038cc1
parentdab2116fa38e7d83a5fb83cef390421f4f99f174 (diff)
downloadrpm-934cf83adf86ef8ee3f3e08c7a666bcf4436f0c8.tar.gz
Trap division by zero in expression parser
(cherry picked from commit 715ce7ce2eb6028553f8ce268a2f6cc76b9d5251) (cherry picked from commit 7c2900e682c95e89d0fc7daf5f4040fd3deb0241)
-rw-r--r--rpmio/expression.c4
-rw-r--r--tests/rpmmacro.at2
2 files changed, 6 insertions, 0 deletions
diff --git a/rpmio/expression.c b/rpmio/expression.c
index 7c30fe711..4221bb9e3 100644
--- a/rpmio/expression.c
+++ b/rpmio/expression.c
@@ -453,6 +453,10 @@ static Value doMultiplyDivide(ParseState state)
if (valueIsInteger(v1)) {
int i1 = v1->data.i, i2 = v2->data.i;
+ if ((i2 == 0) && (op == TOK_DIVIDE)) {
+ exprErr(state, _("division by zero"), NULL);
+ goto err;
+ }
valueFree(v1);
if (op == TOK_MULTIPLY)
v1 = valueMakeInteger(i1 * i2);
diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at
index 9af506e62..930672203 100644
--- a/tests/rpmmacro.at
+++ b/tests/rpmmacro.at
@@ -274,6 +274,7 @@ runroot rpm --eval '%{expr:a*1}'
runroot rpm --eval '%{expr:(5+1)*4)}'
runroot rpm --eval '%{expr:a=!b}'
runroot rpm --eval '%{expr:4+}'
+runroot rpm --eval '%{expr:1/0}'
],
[1],
[],
@@ -283,6 +284,7 @@ error: ^
error: syntax error while parsing ==: a=!b
error: ^
error: unexpected end of expression: 4+
+error: division by zero: 1/0
])
AT_CLEANUP