git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] config: don't segfault when given --path with a missing value
@ 2012-11-14  4:50 Carlos Martín Nieto
  2012-11-15 16:08 ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Martín Nieto @ 2012-11-14  4:50 UTC (permalink / raw)
  To: git

When given a variable without a value, such as '[section] var' and
asking git-config to treat it as a path, git_config_pathname returns
an error and doesn't modify its output parameter. show_config assumes
that the call is always successful and sets a variable to indicate
that vptr should be freed. In case of an error however, trying to do
this will cause the program to be killed, as it's pointing to memory
in the stack.

Set the must_free_vptr flag depending on the return value of
git_config_pathname so it's accurate.
---
 builtin/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/config.c b/builtin/config.c
index 442ccc2..60220d5 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -129,8 +129,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
 		else
 			sprintf(value, "%d", v);
 	} else if (types == TYPE_PATH) {
-		git_config_pathname(&vptr, key_, value_);
-		must_free_vptr = 1;
+		must_free_vptr = !git_config_pathname(&vptr, key_, value_);
 	} else if (value_) {
 		vptr = value_;
 	} else {
-- 
1.8.0.316.g291341c

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-11-15 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-14  4:50 [PATCH] config: don't segfault when given --path with a missing value Carlos Martín Nieto
2012-11-15 16:08 ` Jeff King
2012-11-15 16:11   ` Jeff King
2012-11-15 16:18     ` Jeff King
2012-11-15 18:10       ` Carlos Martín Nieto
2012-11-15 18:15         ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).