Fix out-of-bounds error when incorporating email from stdin
authorDmitry Bogatov <KAction@gnu.org>
Fri, 26 Aug 2016 23:03:28 +0000 (02:03 +0300)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sat, 27 Aug 2016 21:14:30 +0000 (23:14 +0200)
Before this patch, if +inbox is empty, following error happened:

$ inc -file - < /dev/null

Incorporating new mail into inbox...

inc: no messages incorporated, continuing...
inc: Bug: message out of bounds

This happened due improper call to `seq_setunseen', which implicitly
assumed that there is at least one message (it does not handle case
where both mp->hghmsg and mh->lowmsg are 0).

Bug does not happens with command `inc -file empty', since file
is checked for being empty before any read attempts.

Signed-off-by: Dmitry Bogatov <KAction@gnu.org>

sbr/seq_setunseen.c
test/tests/inc/test-read-stdin

index d833650..bd57a2c 100644 (file)
@@ -23,6 +23,10 @@ seq_setunseen(struct msgs *mp, int doadd)
        int n;
        char **ap, *cp, *dp;
 
        int n;
        char **ap, *cp, *dp;
 
+       if (mp->lowmsg == 0) {
+               return;
+       }
+
        /*
        ** Get the list of sequences for Unseen-Sequence
        ** and split them.
        /*
        ** Get the list of sequences for Unseen-Sequence
        ** and split them.
index d771d32..96c4e4a 100644 (file)
@@ -64,3 +64,13 @@ Incorporating new mail into inbox...
 !
 rm "$f"
 unset f
 !
 rm "$f"
 unset f
+
+runandcheck "folder +inc-testfolder" <<!
+inc-testfolder+ has no messages
+!
+
+runandcheck "inc +inc-testfolder -file - < /dev/null" <<!
+Incorporating new mail into inc-testfolder...
+
+inc: no messages incorporated, continuing...
+!