From 279f045c49dc96d8ffc58d778acf0fc6cf5a97d3 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 25 Dec 2011 09:13:22 -0800 Subject: [PATCH] sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic. Obtained-from: FreeBSD 227369 --- bin/sh/arith_yacc.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c index fddb200..d916504 100644 --- a/bin/sh/arith_yacc.c +++ b/bin/sh/arith_yacc.c @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/bin/sh/arith_yacc.c,v 1.6 2011/06/26 20:12:05 jilles Exp $ + * $FreeBSD: src/bin/sh/arith_yacc.c,v 1.7 2011/11/08 23:54:39 jilles Exp $ */ #include @@ -136,11 +136,11 @@ do_binop(int op, arith_t a, arith_t b) yyerror("divide error"); return op == ARITH_REM ? a % b : a / b; case ARITH_MUL: - return a * b; + return (uintmax_t)a * (uintmax_t)b; case ARITH_ADD: - return a + b; + return (uintmax_t)a + (uintmax_t)b; case ARITH_SUB: - return a - b; + return (uintmax_t)a - (uintmax_t)b; case ARITH_LSHIFT: return a << b; case ARITH_RSHIFT: -- 1.7.7.2