summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-02-18 11:45:01 -0800
committerJunio C Hamano <gitster@pobox.com>2015-02-18 11:45:01 -0800
commitde15bdb0583a1a65bf1bab47b7bec9bdc03f727a (patch)
tree36d6f1b6626f57b3a0fcfd93958e29b2aa4fcf4d /config.c
parent2c1f554d0ca2c35c213d68d94baf30f11180f4ce (diff)
parent1d0655c15ebf7dfb460466d058daab790ed285b2 (diff)
downloadgit-de15bdb0583a1a65bf1bab47b7bec9bdc03f727a.tar.gz
Merge branch 'jk/config-no-ungetc-eof'
Reading configuration from a blob object, when it ends with a lone CR, use to confuse the configuration parser. * jk/config-no-ungetc-eof: config_buf_ungetc: warn when pushing back a random character config: do not ungetc EOF
Diffstat (limited to 'config.c')
-rw-r--r--config.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/config.c b/config.c
index e5e64dc60f..66c0a51bce 100644
--- a/config.c
+++ b/config.c
@@ -73,8 +73,12 @@ static int config_buf_fgetc(struct config_source *conf)
static int config_buf_ungetc(int c, struct config_source *conf)
{
- if (conf->u.buf.pos > 0)
- return conf->u.buf.buf[--conf->u.buf.pos];
+ if (conf->u.buf.pos > 0) {
+ conf->u.buf.pos--;
+ if (conf->u.buf.buf[conf->u.buf.pos] != c)
+ die("BUG: config_buf can only ungetc the same character");
+ return c;
+ }
return EOF;
}
@@ -235,7 +239,8 @@ static int get_next_char(void)
/* DOS like systems */
c = cf->do_fgetc(cf);
if (c != '\n') {
- cf->do_ungetc(c, cf);
+ if (c != EOF)
+ cf->do_ungetc(c, cf);
c = '\r';
}
}