]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: check config validity before creating rewrite struct
authorJeff King <peff@peff.net>
Thu, 22 Nov 2018 17:31:09 +0000 (12:31 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 12 Jan 2019 02:35:53 +0000 (18:35 -0800)
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>
remote.c

index 7f6277a1451d147fc5af4ae2910e7c40dd330aec..571dab63f675eeb480bcd4cf465d8f54cc6ef998 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -335,14 +335,14 @@ static int handle_config(const char *key, const char *value, void *cb)
                if (!name)
                        return 0;
                if (!strcmp(subkey, "insteadof")) {
-                       rewrite = make_rewrite(&rewrites, name, namelen);
                        if (!value)
                                return config_error_nonbool(key);
+                       rewrite = make_rewrite(&rewrites, name, namelen);
                        add_instead_of(rewrite, xstrdup(value));
                } else if (!strcmp(subkey, "pushinsteadof")) {
-                       rewrite = make_rewrite(&rewrites_push, name, namelen);
                        if (!value)
                                return config_error_nonbool(key);
+                       rewrite = make_rewrite(&rewrites_push, name, namelen);
                        add_instead_of(rewrite, xstrdup(value));
                }
        }