From 88b2142594d5ea1e8385dae5eca81eed1018c555 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 27 Aug 2016 02:03:28 +0300 Subject: [PATCH] Fix out-of-bounds error when incorporating email from stdin 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 --- sbr/seq_setunseen.c | 4 ++++ test/tests/inc/test-read-stdin | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/sbr/seq_setunseen.c b/sbr/seq_setunseen.c index d833650..bd57a2c 100644 --- a/sbr/seq_setunseen.c +++ b/sbr/seq_setunseen.c @@ -23,6 +23,10 @@ seq_setunseen(struct msgs *mp, int doadd) int n; char **ap, *cp, *dp; + if (mp->lowmsg == 0) { + return; + } + /* ** Get the list of sequences for Unseen-Sequence ** and split them. diff --git a/test/tests/inc/test-read-stdin b/test/tests/inc/test-read-stdin index d771d32..96c4e4a 100644 --- a/test/tests/inc/test-read-stdin +++ b/test/tests/inc/test-read-stdin @@ -64,3 +64,13 @@ Incorporating new mail into inbox... ! rm "$f" unset f + +runandcheck "folder +inc-testfolder" <