From fda7c28f8bd3f34cbd1984a3414926dbff940eea Mon Sep 17 00:00:00 2001 From: Bryan Cantrill Date: Tue, 7 Jun 2016 23:40:08 +0000 Subject: OS-5455 mdb can die on divide overflow Reviewed by: Robert Mustacchi Reviewed by: Patrick Mooney --- usr/src/cmd/mdb/common/mdb/mdb_grammar.y | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'usr/src') diff --git a/usr/src/cmd/mdb/common/mdb/mdb_grammar.y b/usr/src/cmd/mdb/common/mdb/mdb_grammar.y index eda38203e5..97ea454627 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_grammar.y +++ b/usr/src/cmd/mdb/common/mdb/mdb_grammar.y @@ -25,7 +25,9 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright (c) 2015, Joyent, Inc. All rights reserved. + */ #include #include @@ -297,6 +299,13 @@ expression: expression '+' expression { $$ = $1 + $3; } if ($3 == 0UL) yyerror("attempted to divide by zero"); + /* + * Annoyingly, x86 generates a #DE when dividing + * LONG_MIN by -1; check for this case explicitly. + */ + if ($1 == LONG_MIN && $3 == -1L) + yyerror("divide overflow"); + $$ = (intmax_t)$1 / (intmax_t)$3; } -- cgit v1.2.3