]> diplodocus.org Git - nmh/commitdiff
Fix bug where a "cur" sequence that was outside the folder allocation limits
authorKen Hornstein <kenh@pobox.com>
Mon, 7 Jan 2013 22:41:27 +0000 (17:41 -0500)
committerKen Hornstein <kenh@pobox.com>
Mon, 7 Jan 2013 22:41:27 +0000 (17:41 -0500)
could trigger a core dump on some systems.

Makefile.am
sbr/m_convert.c
test/sequences/test-out-of-range [new file with mode: 0755]

index 974d9ee2039aaf3acbd1792e93a450547a518ec6..60600ee87b9c49f94d63e5cd40a13715c01cd042 100644 (file)
@@ -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 \
index c88747f09e0de9008adf99e2316b1351a605f726..496978ee9fbfdc4b9a7220a4f0e4baad0f7067bc 100644 (file)
@@ -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 (executable)
index 0000000..0ee7fb7
--- /dev/null
@@ -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 <<EOS
+cur: 120
+test: 121
+EOS
+
+run_test 'mhpath +inbox test' 'mhpath: sequence test empty'
+
+cat > $MH_TEST_DIR/Mail/inbox/.mh_sequences <<EOS
+cur: 120
+test: 121
+EOS
+
+#
+# Yes, this is right.  "cur" is special in that it can refer to messages
+# that don't exist.
+#
+run_test 'mhpath +inbox cur' "$MH_TEST_DIR/Mail/inbox/120"
+
+exit $failed