* [PATCH] configfile: fix EOF handling
@ 2016-08-07 15:01 john
0 siblings, 0 replies; only message in thread
From: john @ 2016-08-07 15:01 UTC (permalink / raw)
Currently we can end up passing EOF to isspace(), which is in fact
libgit's sane_isspace which does:
((sane_ctype[(unsigned char)(x)] & (GIT_SPACE)) != 0)
It is very unlikely that EOF cast to "unsigned char" will end up in a
character that has the GIT_SPACE bit set, but the standard only requires
that EOF be a negative integer, so it could access any value in the
sane_ctype array.
If it does end up returning true for isspace() then this loop will never
terminate, so handle EOF as a special value in the same way as the other
loops in this function.
Signed-off-by: John Keeping <john at keeping.me.uk>
---
configfile.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/configfile.c b/configfile.c
index 5b0d880..e039109 100644
--- a/configfile.c
+++ b/configfile.c
@@ -39,7 +39,9 @@ static int read_config_line(FILE *f, struct strbuf *name, struct strbuf *value)
/* Skip comments and preceding spaces. */
for(;;) {
- if (c == '#' || c == ';')
+ if (c == EOF)
+ return 0;
+ else if (c == '#' || c == ';')
skip_line(f);
else if (!isspace(c))
break;
--
2.9.2.639.g855ae9f
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-08-07 15:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-07 15:01 [PATCH] configfile: fix EOF handling john
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).