summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-03-02 12:18:59 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-05-19 11:12:13 +0100
commit31f8f82a65c11dfe9e57e618446aaff8cc21d84a (patch)
treef1e88e29dea2e2747a87d71ee9461cb92686ffc4
parent9ceafb57b2c91732cf7fc0a2be02808f871d5a8b (diff)
downloadlibgit2-31f8f82a65c11dfe9e57e618446aaff8cc21d84a.tar.gz
diff_driver: detect memory allocation errors when loading diff driver
When searching for a configuration key for the diff driver, we construct the config key by modifying a buffer and then passing it to `git_config_get_multivar_foreach`. We do not check though whether the modification of the buffer actually succeded, so we could in theory end up passing the OOM buffer to the config function. Fix that by checking return codes. While at it, switch to use `git_buf_PUTS` to avoid repetition of the appended string to calculate its length.
-rw-r--r--src/diff_driver.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 0ca652c69..740b5c9a3 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -281,7 +281,9 @@ static int git_diff_driver_load(
/* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */
git_buf_truncate(&name, namelen + strlen("diff.."));
- git_buf_put(&name, "xfuncname", strlen("xfuncname"));
+ if ((error = git_buf_PUTS(&name, "xfuncname")) < 0)
+ goto done;
+
if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) {
if (error != GIT_ENOTFOUND)
@@ -290,7 +292,9 @@ static int git_diff_driver_load(
}
git_buf_truncate(&name, namelen + strlen("diff.."));
- git_buf_put(&name, "funcname", strlen("funcname"));
+ if ((error = git_buf_PUTS(&name, "funcname")) < 0)
+ goto done;
+
if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) {
if (error != GIT_ENOTFOUND)
@@ -305,7 +309,9 @@ static int git_diff_driver_load(
}
git_buf_truncate(&name, namelen + strlen("diff.."));
- git_buf_put(&name, "wordregex", strlen("wordregex"));
+ if ((error = git_buf_PUTS(&name, "wordregex")) < 0)
+ goto done;
+
if ((error = git_config__lookup_entry(&ce, cfg, name.ptr, false)) < 0)
goto done;
if (!ce || !ce->value)