Skip to content

Commit 54e8c11

Browse files
peffgitster
authored andcommitted
remote: check config validity before creating rewrite struct
When parsing url.foo.insteadOf, we call make_rewrite() and only then check to make sure the config value is a string (and return an error if it isn't). This isn't quite a leak, because the struct we allocate is part of a global array, but it does leave a funny half-finished struct. In practice, it doesn't make much difference because we exit soon after due to the config error anyway. But let's flip the order here to avoid leaving a trap for somebody in the future. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 98cdfbb commit 54e8c11

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ static int handle_config(const char *key, const char *value, void *cb)
335335
if (!name)
336336
return 0;
337337
if (!strcmp(subkey, "insteadof")) {
338-
rewrite = make_rewrite(&rewrites, name, namelen);
339338
if (!value)
340339
return config_error_nonbool(key);
340+
rewrite = make_rewrite(&rewrites, name, namelen);
341341
add_instead_of(rewrite, xstrdup(value));
342342
} else if (!strcmp(subkey, "pushinsteadof")) {
343-
rewrite = make_rewrite(&rewrites_push, name, namelen);
344343
if (!value)
345344
return config_error_nonbool(key);
345+
rewrite = make_rewrite(&rewrites_push, name, namelen);
346346
add_instead_of(rewrite, xstrdup(value));
347347
}
348348
}

0 commit comments

Comments
 (0)