From eee409d4e73d9676cbf8bec3aa71c4cd2a83a79a Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Tue, 10 Dec 2019 14:45:02 -0700 Subject: [PATCH] add an infinite loop detector --- src/devctxt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/devctxt.c b/src/devctxt.c index bafd68e..c6a41bb 100755 --- a/src/devctxt.c +++ b/src/devctxt.c @@ -29,6 +29,7 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT { BYTE outcode1, outcode2; INT32 tmp; + int nloop = 0; Log(LDEBUG, "clipping line from (%d, %d) to (%d, %d) against bounding box (%d, %d, %d, %d)", x1 >> CPX, y1 >> CPX, x2 >> CPX, y2 >> CPX, xmin >> CPX, ymin >> CPX, xmax >> CPX, ymax >> CPX); @@ -36,6 +37,11 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT /* Cohen-Sutherland line-clipping algorithm (see Foley & Van Dam, pp. 145-149) */ for (;;) { + if (++nloop == 20) + { + Log(LDEBUG, "POSSIBLE INFINITE LOOP DETECTED - REJECTING"); + return FALSE; + } outcode1 = line_clip_outcode(x1, y1, xmin, ymin, xmax, ymax); outcode2 = line_clip_outcode(x2, y2, xmin, ymin, xmax, ymax); if ((outcode1 & outcode2) != 0)