git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Re* jc/http-clear-finished-pointer

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 27, 2022, 20:41 UTC
Message-ID
<nycvar.QRO.7.76.6.2205272235220.349@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqq7d68ytj8.fsf_-_@gitster.g>
Hi Junio,
On Thu, 26 May 2022, Junio C Hamano wrote:
Show 39 quoted lines
> 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

Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 24 in “What's cooking in git.git (May 2022, #07; Wed, 25)”
  1. Junio C HamanoMay 26, 2022
  2. Victoria DyeMay 26, 2022
  3. Junio C HamanoMay 26, 2022
  4. Ævar Arnfjörð BjarmasonMay 26, 2022
  5. Victoria DyeMay 26, 2022
  6. Ævar Arnfjörð BjarmasonMay 26, 2022
  7. Junio C HamanoMay 26, 2022
  8. tb/cruft-packs (was Re: What's cooking in git.git (May 2022, #07; Wed, 25))Taylor Blau, May 26, 2022
  9. Taylor BlauMay 26, 2022
  10. Junio C HamanoMay 26, 2022
  11. tb/midx-race-in-pack-objects (was Re: What's cooking in git.git (May 2022, #07; Wed, 25))Taylor Blau, May 26, 2022
  12. sg/build-gitweb (was: What's cooking in git.git (May 2022, #07; Wed, 25))Ævar Arnfjörð Bjarmason, May 26, 2022
  13. Junio C HamanoMay 26, 2022
  14. jc/http-clear-finished-pointer (was: What's cooking in git.git (May 2022, #07; Wed, 25))Ævar Arnfjörð Bjarmason, May 26, 2022
  15. Re* jc/http-clear-finished-pointerJunio C Hamano, May 26, 2022
  16. Johannes SchindelinMay 27, 2022
  17. Junio C HamanoMay 27, 2022
  18. Ævar Arnfjörð BjarmasonJun 1, 2022
  19. Junio C HamanoJun 1, 2022
  20. js/bisect-in-c (was: What's cooking in git.git (May 2022, #07; Wed, 25))Ævar Arnfjörð Bjarmason, May 26, 2022
  21. Junio C HamanoMay 26, 2022
  22. Junio C HamanoMay 26, 2022
  23. Ævar Arnfjörð BjarmasonMay 27, 2022
  24. jx/l10n-workflow-change (was: What's cooking in git.git (May 2022, #07; Wed, 25))Ævar Arnfjörð Bjarmason, May 26, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.