builtin/submodule--helper.c: handle missing submodule URLs
commitfbc806acd106ee1c05fd0a0a83b7c59aa79629d8
authorTaylor Blau <me@ttaylorr.com>
Wed, 24 May 2023 19:51:43 +0000 (24 15:51 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 May 2023 20:26:59 +0000 (25 05:26 +0900)
tree72c8fdb61120636422ae06f909daeb80eb333eeb
parent0d1bd1dfb37ef25e1911777c94129fc769ffec38
builtin/submodule--helper.c: handle missing submodule URLs

In e0a862fdaf (submodule helper: convert relative URL to absolute URL if
needed, 2018-10-16), `prepare_to_clone_next_submodule()` lost the
ability to handle URL-less submodules, due to a change from:

    if (repo_get_config_string_const(the_repostiory, sb.buf, &url))
        url = sub->url;

to

    if (repo_get_config_string_const(the_repostiory, sb.buf, &url)) {
        if (starts_with_dot_slash(sub->url) ||
            starts_with_dot_dot_slash(sub->url)) {
                /* ... */
            }
    }

, which will segfault when `sub->url` is NULL, since both
`starts_with_dot_slash()` does not guard its arguments as non-NULL.

Guard the checks to both of the above functions by first checking
whether `sub->url` is non-NULL. There is no need to check whether `sub`
itself is NULL, since we already perform this check earlier in
`prepare_to_clone_next_submodule()`.

By adding a NULL-ness check on `sub->url`, we'll fall into the 'else'
branch, setting `url` to `sub->url` (which is NULL). Before attempting
to invoke `git submodule--helper clone`, check whether `url` is NULL,
and die() if it is.

Reported-by: Tribo Dar <3bodar@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/t7400-submodule-basic.sh