source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Prevent negative arguments to the .ll request from causing
@ 2014-11-20 13:56 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-11-20 13:56 UTC (permalink / raw)
  To: source

Log Message:
-----------
Prevent negative arguments to the .ll request from causing integer
underflow.  Found while preparing an audit of termp.rmargin.

Overflow can also happen, but i see no sane way to deal with it,
so just let it happen.  It doesn't happen for any sane input anyway,
groff behaviour is undefined, and the resulting values are legal, 
even though they are useless.

Modified Files:
--------------
    mdocml:
        term_ascii.c
        term_ps.c

Revision Data
-------------
Index: term_ascii.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ascii.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.39 -r1.40
--- term_ascii.c
+++ term_ascii.c
@@ -159,12 +159,14 @@ ascii_setwidth(struct termp *p, int iop,
 {
 
 	p->rmargin = p->defrmargin;
-	if (0 < iop)
+	if (iop > 0)
 		p->defrmargin += width;
-	else if (0 > iop)
+	else if (iop == 0)
+		p->defrmargin = width ? width : p->lastrmargin;
+	else if (p->defrmargin > width)
 		p->defrmargin -= width;
 	else
-		p->defrmargin = width ? width : p->lastrmargin;
+		p->defrmargin = 0;
 	p->lastrmargin = p->rmargin;
 	p->rmargin = p->maxrmargin = p->defrmargin;
 }
Index: term_ps.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term_ps.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.68 -r1.69
--- term_ps.c
+++ term_ps.c
@@ -635,12 +635,14 @@ ps_setwidth(struct termp *p, int iop, si
 	size_t	 lastwidth;
 
 	lastwidth = p->ps->width;
-	if (0 < iop)
+	if (iop > 0)
 		p->ps->width += width;
-	else if (0 > iop)
+	else if (iop == 0)
+		p->ps->width = width ? width : p->ps->lastwidth;
+	else if (p->ps->width > width)
 		p->ps->width -= width;
 	else
-		p->ps->width = width ? width : p->ps->lastwidth;
+		p->ps->width = 0;
 	p->ps->lastwidth = lastwidth;
 }
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-20 13:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-20 13:56 mdocml: Prevent negative arguments to the .ll request from causing schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).