source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Do not access a NULL pointer if a matrix or square root are
@ 2017-02-12 14:19 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-02-12 14:19 UTC (permalink / raw)
  To: source

Log Message:
-----------
Do not access a NULL pointer if a matrix or square root are empty.
Crashes found by tb@ with afl(1).

Modified Files:
--------------
    mdocml:
        NEWS
        eqn_term.c
    mdocml/regress/eqn/matrix:
        Makefile
    mdocml/regress/eqn/unary:
        sqrt.in
        sqrt.out_ascii
        sqrt.out_html

Added Files:
-----------
    mdocml/regress/eqn/matrix:
        empty.in
        empty.out_ascii
        empty.out_html

Revision Data
-------------
Index: NEWS
===================================================================
RCS file: /home/cvs/mdocml/mdocml/NEWS,v
retrieving revision 1.18
retrieving revision 1.19
diff -LNEWS -LNEWS -u -p -r1.18 -r1.19
--- NEWS
+++ NEWS
@@ -61,6 +61,8 @@ Changes in version 1.14.1, released on F
    block-end macro calling another block-end macro.
  * mdoc(7): Fix NULL dereference if the only child of the head
    of the first .Sh was an empty in-line macro.
+ * eqn(7): Fix NULL dereference in the terminal formatter
+   for empty matrices and empty square roots.
  * mdoc(7): Fix an assertion failure for a .Bd without a type that
    breaks another block.
  * mdoc(7): Fix an assertion failure caused by .Bl -column without .It
Index: eqn_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/eqn_term.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -Leqn_term.c -Leqn_term.c -u -p -r1.8 -r1.9
--- eqn_term.c
+++ eqn_term.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -68,8 +68,10 @@ eqn_box(struct termp *p, const struct eq
 
 	if (bp->pos == EQNPOS_SQRT) {
 		term_word(p, "sqrt");
-		p->flags |= TERMP_NOSPACE;
-		eqn_box(p, bp->first);
+		if (bp->first != NULL) {
+			p->flags |= TERMP_NOSPACE;
+			eqn_box(p, bp->first);
+		}
 	} else if (bp->type == EQN_SUBEXPR) {
 		child = bp->first;
 		eqn_box(p, child);
@@ -93,7 +95,8 @@ eqn_box(struct termp *p, const struct eq
 		}
 	} else {
 		child = bp->first;
-		if (bp->type == EQN_MATRIX && child->type == EQN_LIST)
+		if (bp->type == EQN_MATRIX &&
+		    child != NULL && child->type == EQN_LIST)
 			child = child->first;
 		while (child != NULL) {
 			eqn_box(p,
--- /dev/null
+++ regress/eqn/matrix/empty.in
@@ -0,0 +1,17 @@
+.Dd February 12, 2017
+.Dt MATRIX-EMPTY 1
+.Os OpenBSD
+.Sh NAME
+.Nm matrix-empty
+.Nd empty matrixes
+.Sh DESCRIPTION
+initial text
+.EQ
+left (
+matrix { }
+right )
+left (
+matrix
+right )
+.EN
+final text
--- /dev/null
+++ regress/eqn/matrix/empty.out_html
@@ -0,0 +1 @@
+<mrow><mfenced open="(" close=")"><mrow></mrow></mfenced><mfenced open="(" close=")"><mrow></mrow></mfenced></mrow>
--- /dev/null
+++ regress/eqn/matrix/empty.out_ascii
@@ -0,0 +1,9 @@
+MATRIX-EMPTY(1)             General Commands Manual            MATRIX-EMPTY(1)
+
+N\bNA\bAM\bME\bE
+     m\bma\bat\btr\bri\bix\bx-\b-e\bem\bmp\bpt\bty\by - empty matrixes
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     initial text () () final text
+
+OpenBSD                        February 12, 2017                       OpenBSD
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/eqn/matrix/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/matrix/Makefile -Lregress/eqn/matrix/Makefile -u -p -r1.1 -r1.2
--- regress/eqn/matrix/Makefile
+++ regress/eqn/matrix/Makefile
@@ -1,6 +1,6 @@
 # $OpenBSD: Makefile,v 1.1.1.1 2015/01/01 12:53:46 schwarze Exp $
 
-REGRESS_TARGETS	 = basic
-HTML_TARGETS	 = basic
+REGRESS_TARGETS	 = basic empty
+HTML_TARGETS	 = basic empty
 
 .include <bsd.regress.mk>
Index: sqrt.out_html
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/eqn/unary/sqrt.out_html,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/unary/sqrt.out_html -Lregress/eqn/unary/sqrt.out_html -u -p -r1.1 -r1.2
--- regress/eqn/unary/sqrt.out_html
+++ regress/eqn/unary/sqrt.out_html
@@ -1 +1 @@
-<mrow><mi>r</mi><mi>=</mi><msqrt><mrow><msup><mi>x</mi><mi>2</mi></msup><mi>+</mi><msup><mi>y</mi><mi>2</mi></msup></mrow></msqrt></mrow>
+<mrow><mi>r</mi><mi>=</mi><msqrt><mrow><msup><mi>x</mi><mi>2</mi></msup><mi>+</mi><msup><mi>y</mi><mi>2</mi></msup></mrow></msqrt><mi>+</mi><msqrt><mrow></mrow></msqrt><mi>+</mi><msqrt></msqrt></mrow>
Index: sqrt.out_ascii
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/eqn/unary/sqrt.out_ascii,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/unary/sqrt.out_ascii -Lregress/eqn/unary/sqrt.out_ascii -u -p -r1.1 -r1.2
--- regress/eqn/unary/sqrt.out_ascii
+++ regress/eqn/unary/sqrt.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      u\bun\bna\bar\bry\by-\b-s\bsq\bqr\brt\bt - square root
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text r = sqrt(x^2 + y^2) final text
+     initial text r = sqrt(x^2 + y^2) + sqrt() + sqrt final text
 
-OpenBSD                        October 10, 2014                        OpenBSD
+OpenBSD                        February 12, 2017                       OpenBSD
Index: sqrt.in
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/eqn/unary/sqrt.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/unary/sqrt.in -Lregress/eqn/unary/sqrt.in -u -p -r1.1 -r1.2
--- regress/eqn/unary/sqrt.in
+++ regress/eqn/unary/sqrt.in
@@ -1,4 +1,4 @@
-.Dd October 10, 2014
+.Dd February 12, 2017
 .Dt UNARY-SQRT 1
 .Os OpenBSD
 .Sh NAME
@@ -7,6 +7,6 @@
 .Sh DESCRIPTION
 initial text
 .EQ
-r = sqrt { x sup 2 + y sup 2 }
+r = sqrt { x sup 2 + y sup 2 } + sqrt { } + sqrt
 .EN
 final text
--
 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:[~2017-02-12 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-12 14:19 mdocml: Do not access a NULL pointer if a matrix or square root are 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).