config: handle NULL value when parsing non-bools
When the config parser sees an "implicit" bool like:
[core]
someVariable
it passes NULL to the config callback. Any callback code which expects a
string must check for NULL. This usually happens via helpers like
git_config_string(), etc, but some custom code forgets to do so and will
segfault.
These are all fairly vanilla cases where the solution is just the usual
pattern of:
if (!value)
return config_error_nonbool(var);
though note that in a few cases we have to split initializers like:
int some_var = initializer();
into:
int some_var;
if (!value)
return config_error_nonbool(var);
some_var = initializer();
There are still some broken instances after this patch, which I'll
address on their own in individual patches after this one.
Reported-by: Carlos Andrés Ramírez Cataño <antaigroupltda@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
564d0252ca
commit
ba176db511
@ -3204,7 +3204,7 @@ static int git_pack_config(const char *k, const char *v,
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(k, "uploadpack.blobpackfileuri")) {
|
||||
struct configured_exclusion *ex = xmalloc(sizeof(*ex));
|
||||
struct configured_exclusion *ex;
|
||||
const char *oid_end, *pack_end;
|
||||
/*
|
||||
* Stores the pack hash. This is not a true object ID, but is
|
||||
@ -3212,6 +3212,10 @@ static int git_pack_config(const char *k, const char *v,
|
||||
*/
|
||||
struct object_id pack_hash;
|
||||
|
||||
if (!v)
|
||||
return config_error_nonbool(k);
|
||||
|
||||
ex = xmalloc(sizeof(*ex));
|
||||
if (parse_oid_hex(v, &ex->e.oid, &oid_end) ||
|
||||
*oid_end != ' ' ||
|
||||
parse_oid_hex(oid_end + 1, &pack_hash, &pack_end) ||
|
||||
|
||||
Reference in New Issue
Block a user