Re: [PATCH v2 4/6] connect: move error check to caller of parse_connect_url
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jul 29, 2015, 20:32 UTC
- Message-ID
- <CAPig+cRGw6-QhYzxkqVE-psQLHORioGmNFbf3Q72nrsSiES5GA@mail.gmail.com>
- In-Reply-To
- <1438185076-28870-5-git-send-email-ps@pks.im>
On Wed, Jul 29, 2015 at 11:51 AM, Patrick Steinhardt <ps@pks.im> wrote:
Show 18 quoted lines
> parse_connect_url() checks if the path component of the URL is
> empty and if so causes the program to die. As the function is to
> be used at other call sites which do not require this check, move
> up the error checking to the existing caller.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> diff --git a/connect.c b/connect.c
> index bdbcee4..e8b813d 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -613,9 +613,6 @@ enum protocol parse_connect_url(const char *url_orig, char **ret_host,
> else
> path = strchr(end, separator);
>
> - if (!path || !*path)
> - die("No path specified. See 'man git-pull' for valid url syntax");
> -Given that there are several dereferences of 'path' following this bit of code, won't this change lead to a crash when path==NULL?
Show 15 quoted lines
> /*
> * null-terminate hostname and point path to ~ for URL's like this:
> * ssh://host.xz/~user/repo
> @@ -665,6 +662,9 @@ struct child_process *git_connect(int fd[2], const char *url,
> signal(SIGCHLD, SIG_DFL);
>
> protocol = parse_connect_url(url, &hostandport, &path);
> + if (!path || !*path)
> + die("No path specified. See 'man git-pull' for valid url syntax");
> +
> if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
> printf("Diag: url=%s\n", url ? url : "NULL");
> printf("Diag: protocol=%s\n", prot_name(protocol));
> --
> 2.5.0