path: root/builtin/mailsplit.c
diff options
authorJohannes Schindelin <>2017-05-04 13:56:14 (GMT)
committerJunio C Hamano <>2017-05-08 03:18:19 (GMT)
commitf0733c13ed8b79bb10e240c4b4a6630784c7d258 (patch)
tree2f388aa60e8c672f32dc8926163f2d7ccaa51530 /builtin/mailsplit.c
parente7b65e205af88755567c3283ee29ca9fb9af11a9 (diff)
mailinfo & mailsplit: check for EOF while parsing
While POSIX states that it is okay to pass EOF to isspace() (and it seems to be implied that EOF should *not* be treated as whitespace), and also to pass EOF to ungetc() (which seems to be intended to fail without buffering the character), it is much better to handle these cases explicitly. Not only does it reduce head-scratching (and helps static analysis avoid reporting false positives), it also lets us handle files containing nothing but whitespace by erroring out. Reported via Coverity. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/mailsplit.c')
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 3068168..664400b 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -232,6 +232,16 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
do {
peek = fgetc(f);
+ if (peek == EOF) {
+ if (f == stdin)
+ /* empty stdin is OK */
+ ret = skip;
+ else {
+ fclose(f);
+ error(_("empty mbox: '%s'"), file);
+ }
+ goto out;
+ }
} while (isspace(peek));
ungetc(peek, f);