From: Philipp Takacs Date: Wed, 2 Jan 2019 15:14:21 +0000 (+0100) Subject: pick fix segfault X-Git-Tag: mmh-0.4~6 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=1a1646dc54cace9984b36a1c12e1831d51fa89f1 pick fix segfault pick now copy the static memory which is later freed. Also fix the access to uninitialized variable in getthreadid(). Thanks c_14 for reporting. --- diff --git a/sbr/getthreadid.c b/sbr/getthreadid.c index 99a7d67..41e3e22 100644 --- a/sbr/getthreadid.c +++ b/sbr/getthreadid.c @@ -47,6 +47,9 @@ threadid(char *msgid, char *referens) char *cp; threadfrom = referens ? referens : msgid; + if (!threadfrom) { + return NULL; + } start = strchr(threadfrom, '<'); end = strchr(start, '>'); diff --git a/test/tests/pick/test-thread b/test/tests/pick/test-thread new file mode 100644 index 0000000..0397e11 --- /dev/null +++ b/test/tests/pick/test-thread @@ -0,0 +1,25 @@ +#!/bin/sh +###################################################### +# +# Test that the -thread option works. +# +###################################################### + +expected_err=$MH_TEST_DIR/$$.expected_err +expected_out=$MH_TEST_DIR/$$.expected_out +actual_err=$MH_TEST_DIR/$$.actual_err +actual_out=$MH_TEST_DIR/$$.actual_out + +# All messages should be go to stdout +cp `mhpath 5` 5.old +anno -component 'Message-Id' -text '' 5 -nodate +cat > $expected_out < $expected_err + +pick -thread 5 > $actual_out 2> $actual_err +mv 5.old `mhpath 5` +diff -u $expected_err $actual_err +diff -u $expected_out $actual_out diff --git a/test/tests/pick/test-thread-without-msgid b/test/tests/pick/test-thread-without-msgid new file mode 100644 index 0000000..d693439 --- /dev/null +++ b/test/tests/pick/test-thread-without-msgid @@ -0,0 +1,22 @@ +#!/bin/sh +###################################################### +# +# Test that the -thread option works. +# +###################################################### + +expected_err=$MH_TEST_DIR/$$.expected_err +expected_out=$MH_TEST_DIR/$$.expected_out +actual_err=$MH_TEST_DIR/$$.actual_err +actual_out=$MH_TEST_DIR/$$.actual_out + +# All messages should be go to stdout +cat > $expected_out < $expected_err + +pick -thread 5 > $actual_out 2> $actual_err +diff -u $expected_err $actual_err +diff -u $expected_out $actual_out diff --git a/uip/pick.c b/uip/pick.c index aba0c02..049be8a 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -1366,7 +1366,7 @@ createonethread(char *c) bd->left = left; bd->right = right; - gd->header = "message-id"; + gd->header = mh_xstrdup("message-id"); snprintf(buf, sizeof(buf), "^[ \t]*<%s>", c); if(!gcompile(gd, buf)) { @@ -1375,7 +1375,7 @@ createonethread(char *c) } gd = right->data; - gd->header = "references"; + gd->header = mh_xstrdup("references"); snprintf(buf, sizeof(buf), "^[ \t]*<%s>", c); if(!gcompile(gd, buf)) {