From 3735bf6af56ea9e15997dd7e07887666b066472a Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Sun, 6 Jan 2013 20:23:53 +0000 Subject: [PATCH] cmd: Avoid division by zero in set /a with %. --- programs/cmd/builtins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 45907690c91..0937dcdb58e 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -3661,6 +3661,7 @@ static int WCMD_reduce(OPSTACK **opstack, VARSTACK **varstack) { WCMD_pushnumber(NULL, var2&var1, varstack); break; case '%': var2 = WCMD_popnumber(varstack); + if (var1 == 0) return WCMD_DIVIDEBYZERO; WCMD_pushnumber(NULL, var2%var1, varstack); break; case '^': var2 = WCMD_popnumber(varstack);