threads / patch / 11996

patchcommit.c: guard config parser from value=NULL

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

## tl;dr

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

replies: 1people: 2as markdown or json

Govind Salinas· Feb 9, 2008, 20:16 UTC · lore
Signed-off-by: Govind Salinas <blix@sophiasuchtig.com>
---
 config.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to config.c +2 −2
diff --git a/config.c b/config.c
index 498259e..8247e88 100644
--- a/config.c
+++ b/config.c
@@ -407,12 +407,12 @@ 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;
 	}

-	if (!strcmp(var, "user.email")) {
+	if (value && !strcmp(var, "user.email")) {
 		strlcpy(git_default_email, value, sizeof(git_default_email));
 		return 0;
 	}
-- 
1.5.4.36.g9af61
Junio C Hamano· Feb 10, 2008, 02:57 UTC · re: Govind Salinas · lore

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

"Govind Salinas" <govind@sophiasuchtig.com> writes:
Show 5 quoted lines
> -	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.

← back to recent threads