git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>, git@vger.kernel.org
Subject: Re: Re* jc/http-clear-finished-pointer
Date: Fri, 27 May 2022 22:41:09 +0200 (CEST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.2205272235220.349@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <xmqq7d68ytj8.fsf_-_@gitster.g>

Hi Junio,

On Thu, 26 May 2022, Junio C Hamano wrote:

> diff --git a/http.c b/http.c
> index 229da4d148..9a98372f74 100644
> --- a/http.c
> +++ b/http.c
> @@ -1367,6 +1367,32 @@ void run_active_slot(struct active_request_slot *slot)
>  			select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
>  		}
>  	}
> +
> +	/*
> +	 * The value of slot->finished we set before the loop was used
> +	 * to set our "finished" variable when our request completed.
> +	 *
> +	 * 1. The slot may not have been reused for another requst
> +	 *    yet, in which case it still has &finished.
> +	 *
> +	 * 2. The slot may already be in-use to serve another request,
> +	 *    which can further be divided into two cases:
> +	 *
> +	 * (a) If call run_active_slot() hasn't been called for that
> +	 *     other request, slot->finished may still have the
> +	 *     address of our &finished.
> +	 *
> +	 * (b) If the request did call run_active_slot(), then the
> +	 *     call would have updated slot->finished at the beginning
> +	 *     of this function, and with the clearing of the member
> +	 *     below, we would find that slot->finished is now NULL.
> +	 *
> +	 * In all cases, slot->finished has no useful information to
> +	 * anybody at this point.  Some compilers warn us for
> +	 * attempting to smuggle a pointer that is about to become
> +	 * invalid, i.e. &finished.  We clear it here to assure them.
> +	 */
> +	slot->finished = NULL;
>  }
>
>  static void release_active_slot(struct active_request_slot *slot)
> --
> 2.36.1-306-g0dbcc0e187

I just verified that there is currently no other location in Git's code
that assigns a non-NULL value to `slot->finished` than
`run_active_slot()`. Otherwise we would potentially overwrite the value
here (which is why I preferred the conditional assignment, which does not
shut up GCC though). So for now, this solution is safe.

Having said that, it is quite puzzling that GCC thinks it is safe to
assign a local variable's pointer to a struct that is then accessed
outside the current file. This would make it easy to copy and use the
pointer well after the function scope was left. This is _not_ the case in
Git's source code, but GCC seems that this isn't possible by
(mis-)interpreting the final `slot->finished = NULL` to mean that the
`slot->finished = &finished` was safe (because it clearly isn't). In GCC's
defense, there is probably a lot of code out there that would no longer
compile if they truly enforced the new `-Wdangling-pointer` rule
correctly.

With all that, here is my ACK.

Ciao,
Dscho

  reply	other threads:[~2022-05-27 20:41 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26  8:41 What's cooking in git.git (May 2022, #07; Wed, 25) Junio C Hamano
2022-05-26 16:02 ` Victoria Dye
2022-05-26 17:23   ` Junio C Hamano
2022-05-26 18:02     ` Ævar Arnfjörð Bjarmason
2022-05-26 18:30     ` Victoria Dye
2022-05-26 18:40       ` Ævar Arnfjörð Bjarmason
2022-05-26 23:10       ` Junio C Hamano
2022-05-26 18:08 ` tb/cruft-packs (was Re: What's cooking in git.git (May 2022, #07; Wed, 25)) Taylor Blau
2022-05-26 18:10 ` What's cooking in git.git (May 2022, #07; Wed, 25) Taylor Blau
2022-05-26 20:17   ` Junio C Hamano
2022-05-26 18:11 ` tb/midx-race-in-pack-objects (was Re: What's cooking in git.git (May 2022, #07; Wed, 25)) Taylor Blau
2022-05-26 18:49 ` sg/build-gitweb (was: " Ævar Arnfjörð Bjarmason
2022-05-26 19:06   ` sg/build-gitweb Junio C Hamano
2022-05-26 18:51 ` jc/http-clear-finished-pointer (was: What's cooking in git.git (May 2022, #07; Wed, 25)) Ævar Arnfjörð Bjarmason
2022-05-26 19:37   ` Re* jc/http-clear-finished-pointer Junio C Hamano
2022-05-27 20:41     ` Johannes Schindelin [this message]
2022-05-27 21:35       ` Junio C Hamano
2022-06-01  7:26     ` Ævar Arnfjörð Bjarmason
2022-06-01 15:48       ` Junio C Hamano
2022-05-26 18:54 ` js/bisect-in-c (was: What's cooking in git.git (May 2022, #07; Wed, 25)) Ævar Arnfjörð Bjarmason
2022-05-26 19:38   ` js/bisect-in-c Junio C Hamano
2022-05-26 20:00     ` js/bisect-in-c Junio C Hamano
2022-05-27 12:52       ` js/bisect-in-c Ævar Arnfjörð Bjarmason
2022-05-26 18:57 ` jx/l10n-workflow-change (was: What's cooking in git.git (May 2022, #07; Wed, 25)) Ævar Arnfjörð Bjarmason

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.2205272235220.349@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).