diff options
author | Jeff King <peff@peff.net> | 2020-04-10 15:47:51 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-04-10 14:56:45 -0700 |
commit | 6a9c235eb4ba32701450aff2c989792b818e02b6 (patch) | |
tree | 5d137fafe6742e9e797697cd24a24d8b48d8e6c4 /INSTALL | |
parent | git_config_parse_key(): return baselen as size_t (diff) | |
download | tgif-6a9c235eb4ba32701450aff2c989792b818e02b6.tar.xz |
config: use size_t to store parsed variable baselen
Most of the config parsing infrastructure is limited in what it can
parse only by the size of memory, because it parses character by
character, building up strbufs for keys, values, etc. One exception is
the "baselen" value we keep in git_parse_source(), which is an int.
That stores the length of the section.subsection base, to which we can
then append individual key names (by truncating back to the baselen with
strbuf_setlen(), and then appending characters for the key name). But
because it's an int, if we see an absurdly long section or subsection,
we may overflow the integer, wrapping negative. That negative value is
then implicitly cast to a size_t when we pass it to strbuf_setlen(),
creating a very large value and triggering a BUG. For example:
$ {
printf '[foo "'
perl -e 'print "a" x 2**31'
echo '"]bar = value'
} >huge
$ git config --file=huge --list
fatal: BUG: strbuf_setlen() beyond buffer
While this is obviously a silly case that we don't care about
supporting, it's worth fixing it by switching to a size_t for a few
reasons:
- we should try to avoid hitting BUG assertions at all
- avoiding integer truncation or overflow sets a good example and
makes it easier to audit the code for more important issues
- the BUG outcome is what happens in _this_ instance, because we wrap
negative. If we used a 2**32 subsection, we'd wrap to a small
positive value and actually generate wrong output (the subsection of
our key would be truncated).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'INSTALL')
0 files changed, 0 insertions, 0 deletions