From b272c556cc930991994028c72ee487b38dada93c Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Fri, 11 Jan 2019 02:28:29 +0100 Subject: [PATCH] fix logic bug in getthreadid getthreadid now early exit the m_getfld2 loop, if the message-id _and_ the references field is found. Without this the wrong thread-id may found if the message-id field is before the references field. Thanks c_14 for reporting --- sbr/getthreadid.c | 4 +++- test/tests/pick/test-thread | 33 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sbr/getthreadid.c b/sbr/getthreadid.c index 41e3e22..a1ad7a0 100644 --- a/sbr/getthreadid.c +++ b/sbr/getthreadid.c @@ -14,15 +14,17 @@ getthreadid(const char *path) enum state state = FLD2; FILE *file = fopen(path, "r"); - while (state == FLD2 && !msgid && !referens) { + while (state == FLD2 && !(msgid && referens)) { switch (state = m_getfld2(state, &f, file)) { case FLD2: if (strncasecmp("message-id", f.name, f.namelen)==0) { msgid = f.value; f.value = NULL; + f.alloclen = 0; } else if (strncasecmp("references", f.name, f.namelen)==0) { referens = f.value; f.value = NULL; + f.alloclen = 0; } break; default: diff --git a/test/tests/pick/test-thread b/test/tests/pick/test-thread index 0397e11..0ac0eed 100644 --- a/test/tests/pick/test-thread +++ b/test/tests/pick/test-thread @@ -5,21 +5,28 @@ # ###################################################### -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 +. "$MH_TEST_COMMON" # All messages should be go to stdout -cp `mhpath 5` 5.old anno -component 'Message-Id' -text '' 5 -nodate -cat > $expected_out <' 6 -nodate + +runandcheck 'pick -thread 5' < $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 +anno -component 'References' -text '' 6 -nodate -append +runandcheck 'pick -thread 5' <' 6 -nodate +runandcheck 'pick -thread 6' <