diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2017-05-04 15:56:14 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-08 12:18:19 +0900 |
commit | f0733c13ed8b79bb10e240c4b4a6630784c7d258 (patch) | |
tree | 2f388aa60e8c672f32dc8926163f2d7ccaa51530 /builtin | |
parent | status: close file descriptor after reading git-rebase-todo (diff) | |
download | tgif-f0733c13ed8b79bb10e240c4b4a6630784c7d258.tar.xz |
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/mailsplit.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 30681681c1..664400b816 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); |