summaryrefslogtreecommitdiff
path: root/mailinfo.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-05-04 15:56:14 +0200
committerJunio C Hamano <gitster@pobox.com>2017-05-08 12:18:19 +0900
commitf0733c13ed8b79bb10e240c4b4a6630784c7d258 (patch)
tree2f388aa60e8c672f32dc8926163f2d7ccaa51530 /mailinfo.c
parente7b65e205af88755567c3283ee29ca9fb9af11a9 (diff)
downloadgit-f0733c13ed8b79bb10e240c4b4a6630784c7d258.tar.gz
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 'mailinfo.c')
-rw-r--r--mailinfo.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/mailinfo.c b/mailinfo.c
index 68037758f2..f92cb9f729 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -882,7 +882,10 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
for (;;) {
int peek;
- peek = fgetc(in); ungetc(peek, in);
+ peek = fgetc(in);
+ if (peek == EOF)
+ break;
+ ungetc(peek, in);
if (peek != ' ' && peek != '\t')
break;
if (strbuf_getline_lf(&continuation, in))
@@ -1099,6 +1102,10 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
do {
peek = fgetc(mi->input);
+ if (peek == EOF) {
+ fclose(cmitmsg);
+ return error("empty patch: '%s'", patch);
+ }
} while (isspace(peek));
ungetc(peek, mi->input);