Author: John Keeping <john@keeping.me.uk>
configfile: fix EOF handling 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@keeping.me.uk>
configfile.c | 4 +++-
diff --git a/configfile.c b/configfile.c index 5b0d880cb7d2d1da755b2f4bc621a6c460ef4df0..e0391091e147891ca2639142a7b29180030db125 100644 --- a/configfile.c +++ b/configfile.c @@ -39,7 +39,9 @@ strbuf_reset(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;