All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH 10/11] relative_url(): fix incorrect condition
Date: Thu, 16 Jun 2022 10:55:57 -0700	[thread overview]
Message-ID: <xmqqr13otrv6.fsf@gitster.g> (raw)
In-Reply-To: <220616.86k09gwx6i.gmgdl@evledraar.gmail.com> (=?utf-8?B?IsOG?= =?utf-8?B?dmFyIEFybmZqw7Zyw7A=?= Bjarmason"'s message of "Thu, 16 Jun 2022 15:09:38 +0200")

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>> -	while (url) {
>> +	while (*url) {
>>  		if (starts_with_dot_dot_slash_native(url)) {
>>  			url += 3;
>>  			colonsep |= chop_last_dir(&remoteurl, is_relative);
>
> Which I tested with this:
> 	
> 	diff --git a/remote.c b/remote.c
> 	index 9b9bbfe80ec..e049bbb791c 100644
> 	--- a/remote.c
> 	+++ b/remote.c
> 	@@ -2846,14 +2846,17 @@ char *relative_url(const char *remote_url, const char *url,
> 	 	 * When the url starts with '../', remove that and the
> 	 	 * last directory in remoteurl.
> 	 	 */
> 	-	while (url) {
> 	+	while (1) {
> 	 		if (starts_with_dot_dot_slash_native(url)) {
> 	 			url += 3;
> 	 			colonsep |= chop_last_dir(&remoteurl, is_relative);
> 	-		} else if (starts_with_dot_slash_native(url))
> 	+		} else if (starts_with_dot_slash_native(url)) {
> 	 			url += 2;
> 	-		else
> 	-			break;
> 	+		} else if (!*url) {
> 	+			BUG("ran off the end of our url?");
> 	+		} else {
> 	+			break; 
> 	+		}
> 	 	}
> 	 	strbuf_reset(&sb);
> 	 	strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url);
> 	
> Which will fail e.g. on this test in t3420-rebase-autostash.sh:
>
> 	+ git submodule add ./ sub
> 	BUG: remote.c:2856: ran off the end of our url?
> 	Aborted

Sorry, but I am confused.  I do not see the point of that test
before the BUG.

I agree that this loop over url is "we want to loop forever, and
stop immediately when url does not start with ../ or ./" infinite
loop, and it is better written with "while(1)".  If you do not make
any other changes that confuses me, we'll get this:

-	while (*url) {
+	while (1) {
		if (starts_with_dot_dot_slash_native(url)) {
			url += 3;
			colonsep |= chop_last_dir(&remoteurl, is_relative);
		} else if (starts_with_dot_slash_native(url))
			url += 2;
		else
			break;
	}

We know url upon entry is not NULL.  starts_with_dot_*() ends up
calling dir.c:path_match_flags() and the first thing it does is to
return if the byte is not '.'.  So the difference is whether you
leave the loop with the "while" condition, or you fail the two
starts_with_dot_*() calls and hit the "break" at the end in the
loop.

IOW, running of the end of the URL is not a BUG, is it?


  reply	other threads:[~2022-06-16 17:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15 23:35 [PATCH 00/11] Coverity fixes Johannes Schindelin via GitGitGadget
2022-06-15 23:35 ` [PATCH 01/11] mingw: avoid accessing uninitialized memory in `is_executable()` Johannes Schindelin via GitGitGadget
2022-06-16  4:07   ` Junio C Hamano
2022-06-16 19:53   ` René Scharfe
2022-06-16 20:13     ` Junio C Hamano
2022-06-16 20:20       ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 02/11] fsmonitor: avoid memory leak in `fsm_settings__get_incompatible_msg()` Johannes Schindelin via GitGitGadget
2022-06-16  4:10   ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 03/11] submodule--helper: avoid memory leak in `update_submodule()` Johannes Schindelin via GitGitGadget
2022-06-16  4:23   ` Junio C Hamano
2022-06-16 17:51     ` Glen Choo
2022-06-15 23:35 ` [PATCH 04/11] get_oid_with_context_1(): avoid use-after-free Johannes Schindelin via GitGitGadget
2022-06-16  4:29   ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 05/11] submodule-config: avoid memory leak Johannes Schindelin via GitGitGadget
2022-06-16  4:36   ` Junio C Hamano
2022-06-16 18:09     ` Glen Choo
2022-06-15 23:35 ` [PATCH 06/11] pack-redundant: avoid using uninitialized memory Johannes Schindelin via GitGitGadget
2022-06-16  4:53   ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 07/11] submodule--helper: avoid memory leak when fetching submodules Johannes Schindelin via GitGitGadget
2022-06-16  4:55   ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 08/11] read_index_from(): avoid memory leak Johannes Schindelin via GitGitGadget
2022-06-17 21:27   ` Tom Levy
2022-06-15 23:35 ` [PATCH 09/11] pack-mtimes: avoid closing a bogus file descriptor Johannes Schindelin via GitGitGadget
2022-06-16 20:43   ` Taylor Blau
2022-06-15 23:35 ` [PATCH 10/11] relative_url(): fix incorrect condition Johannes Schindelin via GitGitGadget
2022-06-16  5:02   ` Junio C Hamano
2022-06-16 13:09   ` Ævar Arnfjörð Bjarmason
2022-06-16 17:55     ` Junio C Hamano [this message]
2022-06-16 16:41   ` Junio C Hamano
2022-06-15 23:35 ` [PATCH 11/11] bug_fl(): add missing `va_end()` call Johannes Schindelin via GitGitGadget
2022-06-16  4:53   ` Jeff King
2022-06-16  5:00     ` Junio C Hamano
2022-06-16 13:02       ` Ævar Arnfjörð Bjarmason
2022-06-16 18:03         ` Junio C Hamano
2022-06-16 19:20           ` Jeff King
2022-06-16 20:04             ` [PATCH] bug_fl(): correctly initialize trace2 va_list Jeff King
2022-06-16 20:11             ` [PATCH 11/11] bug_fl(): add missing `va_end()` call Junio C Hamano
2022-06-16  4:05 ` [PATCH 00/11] Coverity fixes Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqr13otrv6.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.