From: Ken Hornstein Date: Mon, 7 Jan 2013 22:41:27 +0000 (-0500) Subject: Fix bug where a "cur" sequence that was outside the folder allocation limits X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/e8840b36f349b0baa82cc64888e0c99f3614c8b9?hp=--cc Fix bug where a "cur" sequence that was outside the folder allocation limits could trigger a core dump on some systems. --- e8840b36f349b0baa82cc64888e0c99f3614c8b9 diff --git a/Makefile.am b/Makefile.am index 974d9ee2..60600ee8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,6 +76,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \ test/repl/test-multicomp test/repl/test-repl \ test/scan/test-scan test/scan/test-scan-multibyte \ test/sequences/test-flist test/sequences/test-mark \ + test/sequences/test-out-of-range \ test/slocal/test-slocal \ test/whatnow/test-attach-detach test/whatnow/test-cd \ test/whatnow/test-ls test/whom/test-whom \ diff --git a/sbr/m_convert.c b/sbr/m_convert.c index c88747f0..496978ee 100644 --- a/sbr/m_convert.c +++ b/sbr/m_convert.c @@ -181,6 +181,18 @@ single: * check if message is in-range and exists. */ if (mp->msgflags & ALLOW_NEW) { + /* + * We can get into a case where the "cur" sequence is way out + * of range, and because it's allowed to not exist (think + * of "rmm; next") it doesn't get checked to make sure it's + * within the range of messages in seq_init(). So if our + * desired sequence is out of range of the allocated folder + * limits simply reallocate the folder so it's within range. + */ + if (first < mp->lowoff || first > mp->hghoff) + mp = folder_realloc(mp, first < mp->lowoff ? first : mp->lowoff, + first > mp->hghoff ? first : mp->hghoff); + set_select_empty (mp, first); } else { if (first > mp->hghmsg diff --git a/test/sequences/test-out-of-range b/test/sequences/test-out-of-range new file mode 100755 index 00000000..0ee7fb7b --- /dev/null +++ b/test/sequences/test-out-of-range @@ -0,0 +1,37 @@ +#!/bin/sh +############################################################ +# +# Test to see if a out-of-range sequence is handled properly +# +############################################################ + +set -e + +if test -z "${MH_OBJ_DIR}"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "$MH_OBJ_DIR/test/common.sh" + +setup_test + +cat > $MH_TEST_DIR/Mail/inbox/.mh_sequences < $MH_TEST_DIR/Mail/inbox/.mh_sequences <