Commit 31f8f82a by Patrick Steinhardt Committed by Edward Thomson

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.
parent 9ceafb57
...@@ -281,7 +281,9 @@ static int git_diff_driver_load( ...@@ -281,7 +281,9 @@ static int git_diff_driver_load(
/* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */ /* TODO: warn if diff.<name>.command or diff.<name>.textconv are set */
git_buf_truncate(&name, namelen + strlen("diff..")); 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( if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) { cfg, name.ptr, NULL, diff_driver_xfuncname, drv)) < 0) {
if (error != GIT_ENOTFOUND) if (error != GIT_ENOTFOUND)
...@@ -290,7 +292,9 @@ static int git_diff_driver_load( ...@@ -290,7 +292,9 @@ static int git_diff_driver_load(
} }
git_buf_truncate(&name, namelen + strlen("diff..")); 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( if ((error = git_config_get_multivar_foreach(
cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) { cfg, name.ptr, NULL, diff_driver_funcname, drv)) < 0) {
if (error != GIT_ENOTFOUND) if (error != GIT_ENOTFOUND)
...@@ -305,7 +309,9 @@ static int git_diff_driver_load( ...@@ -305,7 +309,9 @@ static int git_diff_driver_load(
} }
git_buf_truncate(&name, namelen + strlen("diff..")); 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) if ((error = git_config__lookup_entry(&ce, cfg, name.ptr, false)) < 0)
goto done; goto done;
if (!ce || !ce->value) if (!ce || !ce->value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment