# [PATCH] guard config parser from value=NULL

3 messages from 2008-02-09 to 2008-02-10. Participants: Martin Koegler, Junio C Hamano.
Thread: https://gitlist.dev/t/11994

## Martin Koegler, 2008-02-09 17:05

Subject: [PATCH] guard config parser from value=NULL
Message-ID: <12025767241532-git-send-email-mkoegler@auto.tuwien.ac.at>
URL: https://gitlist.dev/e/12025767241532-git-send-email-mkoegler%40auto.tuwien.ac.at

```
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
 config.c |   10 +++++-----
 setup.c  |    2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

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, 2008-02-09 21:07

Subject: Re: [PATCH] guard config parser from value=NULL
Message-ID: <7vhcghet3q.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhcghet3q.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <12025767241532-git-send-email-mkoegler@auto.tuwien.ac.at>

```
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.

```

## Martin Koegler, 2008-02-10 17:08

Subject: Re: [PATCH] guard config parser from value=NULL
Message-ID: <20080210170820.GA12162@auto.tuwien.ac.at>
URL: https://gitlist.dev/e/20080210170820.GA12162%40auto.tuwien.ac.at
In-Reply-To: <7vhcghet3q.fsf@gitster.siamese.dyndns.org>

```
On Sat, Feb 09, 2008 at 01:07:53PM -0800, Junio C Hamano wrote:
> 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

```
