From 0d593e1ce1a218332af78b83987543756b0c6cf4 Mon Sep 17 00:00:00 2001 From: David Levine Date: Tue, 8 Aug 2017 20:10:49 -0400 Subject: [PATCH] Fixed scan to handle empty files without violating an assert [Bug #51693]. --- NEWS | 3 ++- sbr/m_getfld.c | 19 +++++++++++-------- test/scan/test-scan | 11 +++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index a59252af..1cb36eb3 100644 --- a/NEWS +++ b/NEWS @@ -122,7 +122,8 @@ BUG FIXES actually works in the absence of a Fcc header in the replied-to message. - A Content-ID is generated for message/external-body entities as required by RFC 2045, even if -nocontentid is supplied to mhbuild. -- Post will now expand aliases on a "From" line when doing a BCC (bug #51098) +- post will now expand aliases on a "From" line when doing a BCC [Bug #51098]. +- scan can now handle empty files without violating an assert [Bug #51693]. ------------------- DEPRECATED FEATURES diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index d74f3869..31bad20f 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -432,17 +432,20 @@ leave_getfld (m_getfld_state_t s) { static size_t read_more (m_getfld_state_t s) { - /* Retain at least edelimlen characters that have already been - read so that we can back up to them in m_Eom(). */ - ssize_t retain = s->edelimlen; + /* Retain at least edelimlen characters that have already been read, + if at least edelimlen have been read, so that we can back up to them + in m_Eom(). */ + ssize_t retain = s->end - s->msg_buf < s->edelimlen ? 0 : s->edelimlen; size_t num_read; - if (retain < s->end - s->readpos) - retain = s->end - s->readpos; - assert (retain <= s->readpos - s->msg_buf); + if (retain > 0) { + if (retain < s->end - s->readpos) + retain = s->end - s->readpos; + assert (retain <= s->readpos - s->msg_buf); - /* Move what we want to retain at end of the buffer to the beginning. */ - memmove (s->msg_buf, s->readpos - retain, retain); + /* Move what we want to retain at end of the buffer to the beginning. */ + memmove (s->msg_buf, s->readpos - retain, retain); + } s->readpos = s->msg_buf + retain; num_read = fread (s->readpos, 1, MSG_INPUT_SIZE, s->iob); diff --git a/test/scan/test-scan b/test/scan/test-scan index dc0e2250..00e383cb 100755 --- a/test/scan/test-scan +++ b/test/scan/test-scan @@ -19,6 +19,9 @@ check_exit '-eq 1' scan - expected="$MH_TEST_DIR/$$.expected" actual="$MH_TEST_DIR/$$.actual" + +# check -width +start_test '-width' cat >"$expected" <> 2 09/29 Test2 Testing message 2<> @@ -35,7 +38,9 @@ EOF run_prog scan +inbox -width 80 >"$actual" || exit 1 check "$expected" "$actual" + # check highlighting +start_test 'highlighting' cat >"$expected" <> 2 09/29 Test2 Testing message 2<> @@ -56,4 +61,10 @@ run_prog scan -form scan.highlighted -width 80 >"$actual" || exit 1 check "$expected" "$actual" +# check null input +start_test 'null input' +run_test 'scan -format "" -file /dev/null' '' + + +finish_test exit $failed -- 2.56.0