From 22bd6b000952af1c83addbfd529269c26dd87c3a Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 18 Dec 2014 17:43:41 +0000 Subject: Don't let the modulo operator divide by zero. Found by jsg@ with afl. --- roff.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'roff.c') diff --git a/roff.c b/roff.c index d2b2d85b..992d9772 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.243 2014/12/16 23:44:41 schwarze Exp $ */ +/* $Id: roff.c,v 1.244 2014/12/18 17:43:41 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -1576,7 +1576,7 @@ roff_evalnum(struct roff *r, int ln, const char *v, *res *= operand2; break; case '/': - if (0 == operand2) { + if (operand2 == 0) { mandoc_msg(MANDOCERR_DIVZERO, r->parse, ln, *pos, v); *res = 0; @@ -1585,6 +1585,12 @@ roff_evalnum(struct roff *r, int ln, const char *v, *res /= operand2; break; case '%': + if (operand2 == 0) { + mandoc_msg(MANDOCERR_DIVZERO, + r->parse, ln, *pos, v); + *res = 0; + break; + } *res %= operand2; break; case '<': -- cgit v1.2.3