threads / patch / 11994

patchguard config parser from value=NULL

Subject: [PATCH] guard config parser from value=NULL

## tl;dr

3 messages between Feb 9, 2008 and Feb 10, 2008. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Martin Koegler· Feb 9, 2008, 17:05 UTC · lore
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
 config.c |   10 +++++-----
 setup.c  |    2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
Show changes to 2 files +6 −6

config.c, setup.c

diff --git a/config.c b/config.c
index 658a11c..b2ea263 100644
--- a/config.c
+++ b/config.c
@@ -416,7 +416,7 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
-	if (!strcmp(var, "user.name")) {
+	if (value && !strcmp(var, "user.name")) {
 		strlcpy(git_default_name, value, sizeof(git_default_name));
 		return 0;
 	}
@@ -426,12 +426,12 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
-	if (!strcmp(var, "i18n.commitencoding")) {
+	if (value && !strcmp(var, "i18n.commitencoding")) {
 		git_commit_encoding = xstrdup(value);
 		return 0;
 	}
 
-	if (!strcmp(var, "i18n.logoutputencoding")) {
+	if (value && !strcmp(var, "i18n.logoutputencoding")) {
 		git_log_output_encoding = xstrdup(value);
 		return 0;
 	}
@@ -442,12 +442,12 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
-	if (!strcmp(var, "core.pager")) {
+	if (value && !strcmp(var, "core.pager")) {
 		pager_program = xstrdup(value);
 		return 0;
 	}
 
-	if (!strcmp(var, "core.editor")) {
+	if (value && !strcmp(var, "core.editor")) {
 		editor_program = xstrdup(value);
 		return 0;
 	}
diff --git a/setup.c b/setup.c
index 23c9a11..8d792dc 100644
--- a/setup.c
+++ b/setup.c
@@ -445,7 +445,7 @@ int check_repository_format_version(const char *var, const char *value)
 		is_bare_repository_cfg = git_config_bool(var, value);
 		if (is_bare_repository_cfg == 1)
 			inside_work_tree = -1;
-	} else if (strcmp(var, "core.worktree") == 0) {
+	} else if (value && strcmp(var, "core.worktree") == 0) {
 		if (git_work_tree_cfg)
 			free(git_work_tree_cfg);
 		git_work_tree_cfg = xstrdup(value);
-- 
1.5.4.gbd71f
Junio C Hamano· Feb 9, 2008, 21:07 UTC · re: Martin Koegler · lore

Re: [PATCH] guard config parser from value=NULL

Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
Show 9 quoted lines
> @@ -416,7 +416,7 @@ int git_default_config(const char *var, const char *value)
>  		return 0;
>  	}
>  
> -	if (!strcmp(var, "user.name")) {
> +	if (value && !strcmp(var, "user.name")) {
>  		strlcpy(git_default_name, value, sizeof(git_default_name));
>  		return 0;
>  	}
This is wrong, isn't it?  When somebody says
	[user]
        	name

we should not silently ignore it, but instead say "user.name is not a bool!" and error out.

The same comment applies to all other
	if (value && !strcmp(var, "<varname>"))
conversions.
Martin Koegler· Feb 10, 2008, 17:08 UTC · re: Junio C Hamano · lore

Re: [PATCH] guard config parser from value=NULL

On Sat, Feb 09, 2008 at 01:07:53PM -0800, Junio C Hamano wrote:
Show 25 quoted lines
> Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
> 
> > @@ -416,7 +416,7 @@ int git_default_config(const char *var, const char *value)
> >  		return 0;
> >  	}
> >  
> > -	if (!strcmp(var, "user.name")) {
> > +	if (value && !strcmp(var, "user.name")) {
> >  		strlcpy(git_default_name, value, sizeof(git_default_name));
> >  		return 0;
> >  	}
> 
> This is wrong, isn't it?  When somebody says
> 
> 	[user]
>         	name
> 
> we should not silently ignore it, but instead say "user.name is
> not a bool!" and error out.
> 
> The same comment applies to all other
> 
> 	if (value && !strcmp(var, "<varname>"))
> 
> conversions.
For all in config.c, yes.

For setup.c, I would say no. The code is called, when trying to find a git repository.

I have seen, that a similar patch for the config.c stuff has been posted. I will wait some days to see, what happens with it.

mfg Martin Kögler

← back to recent threads