diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-05 09:18:59 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-05 09:18:59 -0500 |
| commit | 83a1e614fa4435d8708792202e4f2f2c0b3ce51f (patch) | |
| tree | 11f3d9a1fbc5690d9b5703e7ba59f04982610e84 /src | |
| parent | 50b4d53ef3897fd4066cd74734f4a6e141a64201 (diff) | |
| download | libgit2-83a1e614fa4435d8708792202e4f2f2c0b3ce51f.tar.gz | |
config: handle empty conditional in includeIf
When a config file contains `[includeIf]` (with no condition), we should
treat that as a falsey value. This means that we should properly parse
a config value of `includeIf.path`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config_file.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/config_file.c b/src/config_file.c index 11b444094..91446df09 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -724,14 +724,23 @@ static const struct { static int parse_conditional_include(config_file_parse_data *parse_data, const char *section, const char *file) { char *condition; - size_t i; + size_t section_len, i; int error = 0, matches; if (!parse_data->repo || !file) return 0; - condition = git__substrdup(section + strlen("includeIf."), - strlen(section) - strlen("includeIf.") - strlen(".path")); + section_len = strlen(section); + + /* + * We checked that the string starts with `includeIf.` and ends + * in `.path` to get here. Make sure it consists of more. + */ + if (section_len < CONST_STRLEN("includeIf.") + CONST_STRLEN(".path")) + return 0; + + condition = git__substrdup(section + CONST_STRLEN("includeIf."), + section_len - CONST_STRLEN("includeIf.") - CONST_STRLEN(".path")); for (i = 0; i < ARRAY_SIZE(conditions); i++) { if (git__prefixcmp(condition, conditions[i].prefix)) |
