Merge branch 'of/config-buf-fgetc-unsigned'
The internal config file parser has been updated to treat the content read from a blob as a sequence of unsigned bytes, preventing bytes with the high bit set from being mistakenly interpreted as 'EOF'. * of/config-buf-fgetc-unsigned: config: read the bytes of a blob as unsigned characters
This commit is contained in:
commit
21e0d223ed
2 files changed
+23
-2
No files matched your search
@@ -92,7 +92,7 @@ static long config_file_ftell(struct config_source *conf)
|
||||
static int config_buf_fgetc(struct config_source *conf)
|
||||
{
|
||||
if (conf->u.buf.pos < conf->u.buf.len)
|
||||
return conf->u.buf.buf[conf->u.buf.pos++];
|
||||
return (unsigned char)conf->u.buf.buf[conf->u.buf.pos++];
|
||||
|
||||
return EOF;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ static int config_buf_ungetc(int c, struct config_source *conf)
|
||||
{
|
||||
if (conf->u.buf.pos > 0) {
|
||||
conf->u.buf.pos--;
|
||||
if (conf->u.buf.buf[conf->u.buf.pos] != c)
|
||||
if ((unsigned char)conf->u.buf.buf[conf->u.buf.pos] != c)
|
||||
BUG("config_buf can only ungetc the same character");
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,27 @@ test_expect_success 'can parse blob ending with CR' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'a byte 0xff does not end a blob' '
|
||||
test_commit --printf FF config "# caf\\377\\n[some]\\n\\tkey = value\\n" &&
|
||||
echo value >expect &&
|
||||
git config --blob=HEAD:config some.key >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'a byte 0xff after a CR in a blob' '
|
||||
test_commit --printf CRFF config "# a\\r\\377\\n[some]\\n\\tkey = value\\n" &&
|
||||
echo value >expect &&
|
||||
git config --blob=HEAD:config some.key >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'can parse blob starting with a byte order mark' '
|
||||
test_commit --printf BOM config "\\357\\273\\277[some]\\n\\tkey = value\\n" &&
|
||||
echo value >expect &&
|
||||
git config --blob=HEAD:config some.key >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'config --blob outside of a repository is an error' '
|
||||
nongit test_must_fail git config --blob=foo --list
|
||||
'
|
||||
|
||||
Reference in new issue
Block a user