attila <att...@stalphonsos.com> writes:

> attila <att...@stalphonsos.com> writes:
>
>> attila <att...@stalphonsos.com> writes:
>>
>>> attila <att...@stalphonsos.com> writes:
>>>
>>>> Michael McConville <mm...@mykolab.com> writes:
>>>>
>>>>> attila wrote:
>>>>>> Ping.
>>>>>>
>>>>>> Just tested that the diff works against recentish i386 snap (22 May).
>>>>>> Patch attached.
>>>>>
>>>>> I can't comment on all of the changes, but this builds and runs fine for
>>>>> me.
>>>>>
>>>>
>>>> Attached is an update that brings us from 4.7.1 to 5.4.0, released 8
>>>> Aug.  It shuffles the patches around because the source tree was
>>>> rearranged and adds support for tests.  Sadly, the tests don't all
>>>> pass.  I think I need a t-dep for something LaTeXish but I'm not sure
>>>> what is best, nor am I sure if that's the only reason for the
>>>> failures.  If anyone has a spare cycle or two to look at it I'd
>>>> appreciate it.  If not I'll get back to it by the end of the week.
>>>>
>>>> Pax, -A
>>>
>>> I finally got back to this.  It turns out there wasn't much standing
>>> in the way of the tests working other than me.  Attached is a patch
>>> that brings textproc/multimarkdown up to the latest release (5.4.0
>>> released 5 Aug).  Notable changes:
>>>
>>> * Switched to CMake;
>>> * Ditched the patches I tried and failed to upstream (strcat/sprintf);
>>> * Reworked two remaining patches (HAVE_SRAND_DETERMINISTIC) in the hope
>>>   I might get them upstream;
>>> * Added pledge;
>>> * make test now passes all tests.
>>>
>>> Tested on amd64.
>>>
>>> Comments, feedback most welcome.
>>>
>>> Pax, -A
>>
>> Ping.
>
> I reinstated the strcat/sprintf-related patches but done slightly
> better.  Tests pass on amd64.  Updated patch attached.
>
> Feedback, comments most welcome.
>
> Pax, -A

Finally getting back to this.  Version 5.4.0 is still the latest
stable release (6.0.x exists but is considered beta).  Just tried my
update on the most recent snap and it passess tests and seems to work
for me.  Patch attached.

Feedback most welcome.

Pax, -A
--
https://haqistan.net/~attila | attila@{stalphonsos.com,haqistan.net}
pgp: 0x62A729CF | C2CE 2487 03AC 4C2F 101D  09C1 4068 D5D5 62A7 29CF
Index: Makefile
===================================================================
RCS file: /cvs/ports/textproc/multimarkdown/Makefile,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile
--- Makefile	5 Apr 2015 13:31:15 -0000	1.2
+++ Makefile	1 Oct 2016 18:11:36 -0000
@@ -1,34 +1,45 @@
 # $OpenBSD: Makefile,v 1.2 2015/04/05 13:31:15 sthen Exp $
 
-V =		4.7.1
+V =		5.4.0
 COMMENT =	marked-up plain text to formatted document converter
 DISTNAME =	${GH_PROJECT}-${V}
-PKGNAME =	multimarkdown-${V}
+PKGNAME =	multimarkdown-${V:C/-/./}
 CATEGORIES =	textproc
 
 GH_ACCOUNT =	fletcher
-GH_PROJECT =	MultiMarkdown-4
+GH_PROJECT =	MultiMarkdown-5
 GH_TAGNAME =	${V}
 
+TESTS_COMMIT =	8d5ad66e3bbaeb0de8646783bfe964261ddb39c7
+DIST_SUBDIR =	multimarkdown
+MASTER_SITES_GITHUB =	https://github.com/fletcher/MMD-Test-Suite/archive/
+DISTFILES =	${DISTNAME}${EXTRACT_SUFX} ${TESTS_COMMIT}${EXTRACT_SUFX}
 HOMEPAGE =	http://fletcherpenney.net/multimarkdown/
 MAINTAINER =	Sean Levy <att...@stalphonsos.com>
 
 # Dual licensed: MIT and GPLv2+
 PERMIT_PACKAGE_CDROM =	Yes
 
-WANTLIB += c
+# uses pledge()
+WANTLIB += 	c
 
 BUILD_DEPENDS =	devel/greg
 
-USE_GMAKE =	Yes
-ALL_TARGET =	ALL
-MAKE_FLAGS =	CFLAGS="${CFLAGS} -include GLibFacade.h -DHAVE_ARC4RANDOM" \
-		GREG=${LOCALBASE}/bin/greg
+MODULES =	devel/cmake
 
-# Test files aren't included in distfile.
-NO_TEST =	Yes
+CFLAGS +=	-DHAVE_SRAND_DETERMINISTIC
+
+CONFIGURE_ARGS += -DGREG=${LOCALBASE}/bin/greg
+
+post-extract:
+	rm -rf ${WRKSRC}/submodules/MarkdownTest
+	cp -r ${WRKDIR}/MMD-Test-Suite-${TESTS_COMMIT} \
+		${WRKSRC}/submodules/MarkdownTest
+
+pre-configure:
+	touch ${WRKBUILD}/README.html
 
 do-install:
-	${INSTALL_PROGRAM} ${WRKSRC}/multimarkdown ${PREFIX}/bin/
+	${INSTALL_PROGRAM} ${WRKBUILD}/multimarkdown ${PREFIX}/bin/
 
 .include <bsd.port.mk>
Index: distinfo
===================================================================
RCS file: /cvs/ports/textproc/multimarkdown/distinfo,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 distinfo
--- distinfo	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ distinfo	1 Oct 2016 18:11:36 -0000
@@ -1,2 +1,4 @@
-SHA256 (MultiMarkdown-4-4.7.1.tar.gz) = gy5dzm+hv/TWfmSsLMJPCSCujZEoDlPqh5I3odQ/SGU=
-SIZE (MultiMarkdown-4-4.7.1.tar.gz) = 120896
+SHA256 (multimarkdown/8d5ad66e3bbaeb0de8646783bfe964261ddb39c7.tar.gz) = xGdoX+aZ/y+8ND+LXK24XSgNCccYJV9S6qAW2NI/DKw=
+SHA256 (multimarkdown/MultiMarkdown-5-5.4.0.tar.gz) = HMA4X/1sghwmXpcPgcxOwAnH7Lv7EuDhFce7WzPQmoM=
+SIZE (multimarkdown/8d5ad66e3bbaeb0de8646783bfe964261ddb39c7.tar.gz) = 185408
+SIZE (multimarkdown/MultiMarkdown-5-5.4.0.tar.gz) = 136693
Index: patches/patch-CMakeLists_txt
===================================================================
RCS file: patches/patch-CMakeLists_txt
diff -N patches/patch-CMakeLists_txt
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-CMakeLists_txt	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,14 @@
+$OpenBSD$
+
+Use installed greg
+--- CMakeLists.txt.orig	Mon Feb 22 20:05:02 2016
++++ CMakeLists.txt	Tue Mar 22 12:45:41 2016
+@@ -149,7 +149,7 @@ endif ()
+ # Need to build parser.c via greg
+ add_custom_command (
+ 	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/parser.c
+-	COMMAND ${PROJECT_SOURCE_DIR}/submodules/greg/greg -o ${CMAKE_CURRENT_BINARY_DIR}/parser.c ${PROJECT_SOURCE_DIR}/src/parser.leg
++	COMMAND ${GREG} -o ${CMAKE_CURRENT_BINARY_DIR}/parser.c ${PROJECT_SOURCE_DIR}/src/parser.leg
+ )
+ 
+ # src_files are the primary files, and will be included in doxygen documentation
Index: patches/patch-Makefile
===================================================================
RCS file: patches/patch-Makefile
diff -N patches/patch-Makefile
--- patches/patch-Makefile	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,37 +0,0 @@
-$OpenBSD: patch-Makefile,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-Make it possible to pass GREG=/usr/local/bin/greg in on the
-command line and avoid git submodules.
-
---- Makefile.orig	Mon Mar 23 18:21:56 2015
-+++ Makefile	Mon Mar 23 18:32:22 2015
-@@ -32,18 +32,25 @@ ifeq ($(MAKECMDGOALS),static)
- LDFLAGS += -static -static-libgcc
- endif
- 
--GREG= greg/greg
-+# OUR_GREG: the version of greg in a submodule
-+# GREG: the path to greg we want to use for parser.leg
-+#
-+# This way we can pass GREG=/usr/local/bin/greg in on
-+# the command line if we have greg installed already.
- 
-+OUR_GREG=greg/greg
-+GREG?=$(OUR_GREG)
-+
- ALL : $(PROGRAM) enumMap.txt
- static : $(PROGRAM) enumMap.txt
- 
- %.o : %.c parser.h
- 	$(CC) -c $(CFLAGS) -o $@ $<
- 
--parser.c : parser.leg greg/greg parser.h
--	greg/greg -o parser.c parser.leg
-+parser.c : parser.leg $(GREG) parser.h
-+	$(GREG) -o parser.c parser.leg
- 
--$(GREG): greg
-+$(OUR_GREG): greg
- 	$(MAKE) -C greg
- 
- $(PROGRAM) : $(OBJS)
Index: patches/patch-html_c
===================================================================
RCS file: patches/patch-html_c
diff -N patches/patch-html_c
--- patches/patch-html_c	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,59 +0,0 @@
-$OpenBSD: patch-html_c,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-Switch to using arc4random(3) everywhere, since they don't really want
-repeatability (as evidenced by the arguments they pass to srand(3)).
-
---- html.c.orig	Mon Mar  9 18:52:39 2015
-+++ html.c	Sat Mar 21 15:44:10 2015
-@@ -112,8 +112,12 @@ void print_html_node(GString *out, node *n, scratch_pa
- 				scratch->footnote_para_counter --;
- 				if (scratch->footnote_para_counter == 0) {
- 					if (scratch->extensions & EXT_RANDOM_FOOT) {
-+#ifdef HAVE_ARC4RANDOM
-+						random = arc4random_uniform(99999) + 1;
-+#else
- 						srand(scratch->random_seed_base + scratch->footnote_to_print);
- 						random = rand() % 99999 + 1;
-+#endif
- 					} else {
- 						random = scratch->footnote_to_print;
- 					}
-@@ -574,8 +578,12 @@ void print_html_node(GString *out, node *n, scratch_pa
- 			temp_node = node_for_count(scratch->used_notes, lev);
- 			
- 			if (scratch->extensions & EXT_RANDOM_FOOT) {
-+#ifdef HAVE_ARC4RANDOM
-+				random = arc4random_uniform(99999) + 1;
-+#else
- 				srand(scratch->random_seed_base + lev);
- 				random = rand() % 99999 + 1;
-+#endif
- 			} else {
- 				random = lev;
- 			}
-@@ -628,8 +636,12 @@ void print_html_node(GString *out, node *n, scratch_pa
- 					fprintf(stderr, "matching cite found - %d\n",lev);
- #endif
- 					if (scratch->extensions & EXT_RANDOM_FOOT) {
-+#ifdef HAVE_ARC4RANDOM
-+						random = arc4random_uniform(99999) + 1;
-+#else
- 						srand(scratch->random_seed_base + lev);
- 						random = rand() % 99999 + 1;
-+#endif
- 					} else {
- 						random = lev;
- 					}
-@@ -901,8 +913,12 @@ void print_html_endnotes(GString *out, scratch_pad *sc
- 		pad(out, 1, scratch);
- 		
- 		if (scratch->extensions & EXT_RANDOM_FOOT) {
-+#ifdef HAVE_ARC4RANDOM
-+			random = arc4random_uniform(99999) + 1;
-+#else
- 			srand(scratch->random_seed_base + counter);
- 			random = rand() % 99999 + 1;
-+#endif
- 		} else {
- 			random = counter;
- 		}
Index: patches/patch-latex_c
===================================================================
RCS file: patches/patch-latex_c
diff -N patches/patch-latex_c
--- patches/patch-latex_c	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,29 +0,0 @@
-$OpenBSD: patch-latex_c,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-Switch from strcat(3) to a safer idiom.
-
---- latex.c.orig	Mon Mar  9 18:52:39 2015
-+++ latex.c	Sat Mar 21 15:44:10 2015
-@@ -1202,16 +1202,16 @@ void print_latex_url(GString *out, char *str, scratch_
- char * correct_dimension_units(char *original) {
- 	char *result;
- 	int i;
--	
-+	size_t result_len;
-+
- 	result = strdup(original);
--	
-+	result_len = strlen(result);
-+
- 	for (i = 0; result[i]; i++)
- 		result[i] = tolower(result[i]);
- 	
--	if (strstr(&result[strlen(result)-2],"px")) {
--		result[strlen(result)-2] = '\0';
--		strcat(result, "pt");
--	}
-+	if (strstr(&result[result_len-2],"px"))
-+		result[result_len-1] = 't';
- 	
- 	return result;
- }
Index: patches/patch-parse_utilities_c
===================================================================
RCS file: patches/patch-parse_utilities_c
diff -N patches/patch-parse_utilities_c
--- patches/patch-parse_utilities_c	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,52 +0,0 @@
-$OpenBSD: patch-parse_utilities_c,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-ifdef out pragmas that don't work under OpenBSD.  Use arc4random(3).
-
---- parse_utilities.c.orig	Mon Sep 22 12:57:41 2014
-+++ parse_utilities.c	Wed Jan  7 16:02:19 2015
-@@ -22,7 +22,9 @@
- #include "parser.h"
- #include <libgen.h>
- 
-+#ifndef __OpenBSD__
- #pragma mark - Parse Tree
-+#endif /* __OpenBSD__ */
- 
- /* Create a new node in the parse tree */
- node * mk_node(int key) {
-@@ -219,7 +221,9 @@ void append_list(node *new, node *list) {
- 	}
- }
- 
-+#ifndef __OpenBSD__
- #pragma mark - Parser Data
-+#endif /* __OpenBSD__ */
- 
- /* Create parser data - this is where you stash stuff to communicate 
- 	into and out of the parser */
-@@ -250,7 +254,9 @@ void free_parser_data(parser_data *data) {
- }
- 
- /* mk_scratch_pad -- store stuff here while exporting the result tree */
-+#ifndef HAVE_ARC4RANDOM
- void ran_start(long seed);
-+#endif
- scratch_pad * mk_scratch_pad(unsigned long extensions) {
- 	scratch_pad *result = (scratch_pad *)malloc(sizeof(scratch_pad));
- 	result->extensions = extensions;
-@@ -277,6 +283,7 @@ scratch_pad * mk_scratch_pad(unsigned long extensions)
- 	result->table_alignment = NULL;
- 	result->table_column = 0;
- 
-+#ifndef HAVE_ARC4RANDOM
- 	if (extensions & EXT_RANDOM_FOOT) {
- 	    srand((int)time(NULL));
- 		result->random_seed_base = rand() % 32000;
-@@ -285,6 +292,7 @@ scratch_pad * mk_scratch_pad(unsigned long extensions)
- 		result->random_seed_base = 0;
- 	}
- 	ran_start(310952L);
-+#endif /* !HAVE_ARC4RANDOM */
- 	
- 	result->lyx_para_type = PARA;             /* CRC - Simple paragraph */
- 	result->lyx_level = 0;                    /* CRC - out outside level */
Index: patches/patch-parser_leg
===================================================================
RCS file: patches/patch-parser_leg
diff -N patches/patch-parser_leg
--- patches/patch-parser_leg	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,19 +0,0 @@
-$OpenBSD: patch-parser_leg,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-Switch from sprintf(3) to snprintf(3)
-
---- parser.leg.orig	Mon Mar  9 18:52:39 2015
-+++ parser.leg	Sat Mar 21 15:44:10 2015
-@@ -562,8 +562,10 @@ AutoLinkUrl =   '<' < [A-Za-z]+ "://" ( !Newline !'>' 
- 
- AutoLinkEmail = '<' ( "mailto:" )? < [-A-Za-z0-9+_./!%~$]+ '@' ( !Newline !'>' . )+ > '>'
- 	{
--		char *mailto = malloc(strlen(yytext) + 8);
--		sprintf(mailto, "mailto:%s", yytext);
-+		size_t mailto_len = strlen(yytext) + 8;
-+		char *mailto = malloc(mailto_len);
-+		assert(mailto);
-+		assert(snprintf(mailto,mailto_len,"mailto:%s",yytext) < mailto_len);
- 		$$ = mk_link(str(yytext), NULL, mailto, NULL, NULL);
- 		free(mailto);
- 	}
Index: patches/patch-src_html_c
===================================================================
RCS file: patches/patch-src_html_c
diff -N patches/patch-src_html_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_html_c	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,53 @@
+$OpenBSD$
+
+Use srand_deterministic(3) if available.
+--- src/html.c.orig	Fri Aug  5 09:08:36 2016
++++ src/html.c	Thu Sep 15 15:35:50 2016
+@@ -115,7 +115,11 @@ void print_html_node(GString *out, node *n, scratch_pa
+ 				scratch->footnote_para_counter --;
+ 				if (scratch->footnote_para_counter == 0) {
+ 					if (scratch->extensions & EXT_RANDOM_FOOT) {
++#ifdef HAVE_SRAND_DETERMINISTIC
++						srand_deterministic(scratch->random_seed_base + scratch->footnote_to_print);
++#else
+ 						srand(scratch->random_seed_base + scratch->footnote_to_print);
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 						random = rand() % 99999 + 1;
+ 					} else {
+ 						random = scratch->footnote_to_print;
+@@ -604,7 +608,11 @@ void print_html_node(GString *out, node *n, scratch_pa
+ 			temp_node = node_for_count(scratch->used_notes, lev);
+ 			
+ 			if (scratch->extensions & EXT_RANDOM_FOOT) {
++#ifdef HAVE_SRAND_DETERMINISTIC
++				srand_deterministic(scratch->random_seed_base + lev);
++#else
+ 				srand(scratch->random_seed_base + lev);
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 				random = rand() % 99999 + 1;
+ 			} else {
+ 				random = lev;
+@@ -658,7 +666,11 @@ void print_html_node(GString *out, node *n, scratch_pa
+ 					fprintf(stderr, "matching cite found - %d\n",lev);
+ #endif
+ 					if (scratch->extensions & EXT_RANDOM_FOOT) {
++#ifdef HAVE_SRAND_DETERMINISTIC
++						srand_deterministic(scratch->random_seed_base + lev);
++#else
+ 						srand(scratch->random_seed_base + lev);
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 						random = rand() % 99999 + 1;
+ 					} else {
+ 						random = lev;
+@@ -951,7 +963,11 @@ void print_html_endnotes(GString *out, scratch_pad *sc
+ 		pad(out, 1, scratch);
+ 		
+ 		if (scratch->extensions & EXT_RANDOM_FOOT) {
++#ifdef HAVE_SRAND_DETERMINISTIC
++			srand_deterministic(scratch->random_seed_base + counter);
++#else
+ 			srand(scratch->random_seed_base + counter);
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 			random = rand() % 99999 + 1;
+ 		} else {
+ 			random = counter;
Index: patches/patch-src_latex_c
===================================================================
RCS file: patches/patch-src_latex_c
diff -N patches/patch-src_latex_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_latex_c	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,28 @@
+$OpenBSD$
+
+Switch from strcat(3) to safer idiom, ensure bogus input doesn't result
+in out of bounds pointer.
+--- src/latex.c.orig	Sat Oct  1 11:12:24 2016
++++ src/latex.c	Sat Oct  1 11:23:02 2016
+@@ -1219,16 +1219,16 @@ void print_latex_url(GString *out, char *str, scratch_
+ char * correct_dimension_units(char *original) {
+ 	char *result;
+ 	int i;
++	size_t result_len;
+ 	
+ 	result = strdup(original);
++	result_len = strlen(result);
+ 	
+ 	for (i = 0; result[i]; i++)
+ 		result[i] = tolower(result[i]);
+ 	
+-	if (strstr(&result[strlen(result)-2],"px")) {
+-		result[strlen(result)-2] = '\0';
+-		strcat(result, "pt");
+-	}
+-	
++	if ((result_len > 1) && strstr(&result[result_len-2],"px"))
++		result[result_len-1] = 't';
++
+ 	return result;
+ }
Index: patches/patch-src_multimarkdown_c
===================================================================
RCS file: patches/patch-src_multimarkdown_c
diff -N patches/patch-src_multimarkdown_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_multimarkdown_c	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,25 @@
+$OpenBSD$
+
+Use pledge(2) on OpenBSD.
+--- src/multimarkdown.c.orig	Fri Aug  5 09:08:36 2016
++++ src/multimarkdown.c	Thu Sep 15 17:28:27 2016
+@@ -58,6 +58,7 @@
+ */
+ 
+ 
++#include <errno.h>
+ #include <getopt.h>
+ #include <libgen.h>
+ #include "parser.h"
+@@ -262,6 +263,11 @@ int main(int argc, char **argv)
+ 			abort();
+ 		}
+ 	}	
++	
++	if (pledge("stdio rpath wpath cpath", NULL) == -1) {
++		fprintf(stderr,"pledge: error #%d\n", errno);
++		exit(EXIT_FAILURE);
++	}
+ 	
+ 	/* Compatibility mode emulates the behavior of Markdown.pl */
+ 	if (compatibility_flag) {
Index: patches/patch-src_parse_utilities_c
===================================================================
RCS file: patches/patch-src_parse_utilities_c
diff -N patches/patch-src_parse_utilities_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_parse_utilities_c	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,31 @@
+$OpenBSD$
+
+Use srand_deterministic(3) on OpenBSD
+--- src/parse_utilities.c.orig	Fri Aug  5 09:08:36 2016
++++ src/parse_utilities.c	Thu Sep 15 15:35:50 2016
+@@ -268,10 +268,18 @@ scratch_pad * mk_scratch_pad(unsigned long extensions)
+ 	result->inside_footnote = 0;
+ 
+ 	if (extensions & EXT_RANDOM_FOOT) {
++#ifdef HAVE_SRAND_DETERMINISTIC
++	    srand_deterministic((int)time(NULL));
++#else
+ 	    srand((int)time(NULL));
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 		result->random_seed_base = rand() % 32000;
+ 	} else {
++#ifdef HAVE_SRAND_DETERMINISTIC
++		srand_deterministic(1);
++#else
+ 		srand(1);
++#endif /* HAVE_SRAND_DETERMINISTIC */
+ 		result->random_seed_base = 0;
+ 	}
+ 	ran_start(310952L);
+@@ -909,4 +917,4 @@ char * my_strndup(const char * source, size_t n) {
+ 	result[len] = '\0';
+ 
+ 	return result;
+-}
+\ No newline at end of file
++}
Index: patches/patch-src_parser_leg
===================================================================
RCS file: patches/patch-src_parser_leg
diff -N patches/patch-src_parser_leg
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_parser_leg	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,20 @@
+$OpenBSD$
+
+Switch from sprintf(3) to safer idiom.  Handle errors as elsewhere in code.
+--- src/parser.leg.orig	Fri Aug  5 09:08:36 2016
++++ src/parser.leg	Sat Oct  1 14:05:54 2016
+@@ -637,8 +637,12 @@ AutoLinkUrl =   '<' < [A-Za-z]+ "://" ( !Newline !'>' 
+ 
+ AutoLinkEmail = '<' ( "mailto:" )? < [-A-Za-z0-9+_./!%~$]+ '@' ( !Newline !'>' . )+ > '>'
+ 	{
+-		char *mailto = malloc(strlen(yytext) + 8);
+-		sprintf(mailto, "mailto:%s", yytext);
++		char *mailto = NULL;
++		if (asprintf(&mailto, "mailto:%s", yytext) == -1) {
++			fprintf(stderr, "error copying mailto link: %s\n",
++				yytext);
++			exit(1);
++		}
+ 		$$ = mk_link(str(yytext), NULL, mailto, NULL, NULL);
+ 		free(mailto);
+ 	}
Index: patches/patch-src_writer_c
===================================================================
RCS file: patches/patch-src_writer_c
diff -N patches/patch-src_writer_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_writer_c	1 Oct 2016 18:11:36 -0000
@@ -0,0 +1,43 @@
+$OpenBSD$
+
+Switch from strcat(3) to a safer idiom, make sure bogus dimension does
+not result in out of bounds pointer.
+--- src/writer.c.orig	Sat Oct  1 11:18:59 2016
++++ src/writer.c	Sat Oct  1 11:22:21 2016
+@@ -690,6 +690,7 @@ char * dimension_for_attribute(char *querystring, node
+     int i;
+     char *upper;
+     GString *result;
++    size_t dimension_len;
+ 
+     attribute = node_for_attribute(querystring, list);
+     if (attribute == NULL) return NULL;
+@@ -698,6 +699,7 @@ char * dimension_for_attribute(char *querystring, node
+ #endif
+ 
+     dimension = strdup(attribute->children->str);
++    dimension_len = strlen(dimension);
+     upper = strdup(attribute->children->str);
+ 
+     for(i = 0; dimension[ i ]; i++)
+@@ -709,15 +711,14 @@ char * dimension_for_attribute(char *querystring, node
+ 	fprintf(stderr, "b\n");
+ #endif
+ 
+-    if (strstr(dimension, "px")) {
+-        ptr = strstr(dimension,"px");
+-        ptr[0] = '\0';
+-        strcat(ptr,"pt");
+-    }
++    ptr = strstr(dimension,"px");
++    if (ptr)
++        ptr[1] = 't';
+ 
+     result = g_string_new(dimension);
+     
+-    if ((strcmp(dimension,upper) == 0) && (dimension[strlen(dimension) -1] != '%')) {
++    if ((strcmp(dimension,upper) == 0) && (dimension_len > 0) &&
++        (dimension[dimension_len-1] != '%')) {
+         /* no units */
+         g_string_append_printf(result, "pt");
+     }
Index: patches/patch-writer_c
===================================================================
RCS file: patches/patch-writer_c
diff -N patches/patch-writer_c
--- patches/patch-writer_c	24 Mar 2015 19:16:13 -0000	1.1.1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,42 +0,0 @@
-$OpenBSD: patch-writer_c,v 1.1.1.1 2015/03/24 19:16:13 okan Exp $
-
-Switch from strcat to a safer idiom.
-
---- writer.c.orig	Mon Mar  9 18:52:39 2015
-+++ writer.c	Sat Mar 21 15:44:10 2015
-@@ -648,6 +648,7 @@ char * dimension_for_attribute(char *querystring, node
-     int i;
-     char *upper;
-     GString *result;
-+    size_t dimension_len;
- 
-     attribute = node_for_attribute(querystring, list);
-     if (attribute == NULL) return NULL;
-@@ -655,6 +656,7 @@ char * dimension_for_attribute(char *querystring, node
- 	fprintf(stderr, "a\n");
- #endif
- 
-+    dimension_len = strlen(attribute->children->str);
-     dimension = strdup(attribute->children->str);
-     upper = strdup(attribute->children->str);
- 
-@@ -667,15 +669,13 @@ char * dimension_for_attribute(char *querystring, node
- 	fprintf(stderr, "b\n");
- #endif
- 
--    if (strstr(dimension, "px")) {
--        ptr = strstr(dimension,"px");
--        ptr[0] = '\0';
--        strcat(ptr,"pt");
--    }
-+    ptr = strstr(dimension, "px");
-+    if (ptr)
-+        ptr[1] = 't';
- 
-     result = g_string_new(dimension);
-     
--    if ((strcmp(dimension,upper) == 0) && (dimension[strlen(dimension) -1] != '%')) {
-+    if ((strcmp(dimension,upper) == 0) && (dimension[dimension_len-1] != '%')) {
-         /* no units */
-         g_string_append_printf(result, "pt");
-     }

Reply via email to