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

Re: [PATCH 10/11] bundle-uri: avoid using undefined output of `sscanf()`

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
May 19, 2025, 09:03 UTC
Message-ID
<32de776c-9f15-4030-9f78-76384dd6dbb1@gmail.com>
In-Reply-To
<20250516154250.GA26009@coredump.intra.peff.net>
On 16/05/2025 16:42, Jeff King wrote:
Show 19 quoted lines
> On Fri, May 16, 2025 at 02:40:54PM +0100, Phillip Wood wrote:
> 
>> On 16/05/2025 11:11, Phillip Wood wrote:
>>
>>> I had a similar thought, though to make sure that we parsed 64 bit
>>> values correctly on windows so we'd need something based on strtoumax()
>>> I think.
>>
>> Perhaps something like the diff below which adds strtoul_u64() in a
>> similar vein to strtoul_ui(). I think it's debatable whether we really
>> want to skip leading whitespace so we could perhaps tighten things up
>> by replacing "if (strchr(s, '-'))" with "if (!isdigit(*s))" though
>> that would mean this function would behave slightly differently to
>> strtoul_ui().
> 
> It feels like we would had to have dealt with this before for other
> large values. But poking around at a few obvious suspects (e.g.,
> packSizeLimit), it looks like they are all constrained to "unsigned
> long".
I was surprised by that as well
> So yeah, we probably do need something new. IMHO we should probably have
> repo_config_get_u64() or similar (with the appropriate underlying
> helpers as well) as use it here. But I am happy with any solution.

I think repo_config_get_ulong() and friends all accept a multiplier suffix. That makes sense for things like packSizeLimit but here we're expecting a bare integer. It probably doesn't really matter but as one of the code paths parses a file that comes from the bundle server we might want to be as strict as we can be.

Show 7 quoted lines
> And I do agree that we should consider banning *scanf(). With numeric
> placeholders I don't think they're a security problem (though they are
> easy to get wrnog, as this discussion shows). But using them with "%s"
> should generally be disallowed.
> 
> There is an fscanf() in builtin/gc.c that uses "%s", but it is careful
> to construct a custom format string that limits the string size. Yuck.
Yes that looks pretty horrid
Phillip
> The usual thing in our code base would be to read into a buffer and
> parse from there.
> 
> -Peff
Previous: Jeff KingNext: Jeff King
Message 25 of 36 in “CodeQL-inspired fixes”
  1. 00/11 CodeQL-inspired fixesJohannes Schindelin via GitGitGadget, May 15, 2025
  2. 02/11 fetch: carefully clear local variable's address after useJohannes Schindelin via GitGitGadget, May 15, 2025
  3. Jeff KingMay 15, 2025
  4. 03/11 commit-graph: avoid malloc'ing a local variableJohannes Schindelin via GitGitGadget, May 15, 2025
  5. Jeff KingMay 15, 2025
  6. Junio C HamanoMay 15, 2025
  7. 04/11 upload-pack: rename `enum` to reflect the operationJohannes Schindelin via GitGitGadget, May 15, 2025
  8. Jeff KingMay 15, 2025
  9. 05/11 has_dir_name(): make code more obviousJohannes Schindelin via GitGitGadget, May 15, 2025
  10. Jeff KingMay 15, 2025
  11. 06/11 fetch: avoid unnecessary work when there is no current branchJohannes Schindelin via GitGitGadget, May 15, 2025
  12. Jeff KingMay 15, 2025
  13. 07/11 Avoid redundant conditionsJohannes Schindelin via GitGitGadget, May 15, 2025
  14. Jeff KingMay 15, 2025
  15. 08/11 trace2: avoid "futile conditional"Johannes Schindelin via GitGitGadget, May 15, 2025
  16. Jeff KingMay 15, 2025
  17. 09/11 commit-graph: avoid using stale stack addressesJohannes Schindelin via GitGitGadget, May 15, 2025
  18. Jeff KingMay 15, 2025
  19. 10/11 bundle-uri: avoid using undefined output of `sscanf()`Johannes Schindelin via GitGitGadget, May 15, 2025
  20. Junio C HamanoMay 15, 2025
  21. Jeff KingMay 15, 2025
  22. Phillip WoodMay 16, 2025
  23. Phillip WoodMay 16, 2025
  24. Jeff KingMay 16, 2025
  25. Phillip WoodMay 19, 2025
  26. Jeff KingMay 22, 2025
  27. 11/11 sequencer: stop pretending that an assignment is a conditionJohannes Schindelin via GitGitGadget, May 15, 2025
  28. Junio C HamanoMay 15, 2025
  29. Jeff KingMay 15, 2025
  30. Phillip WoodMay 16, 2025
  31. 01/11 commit: simplify codeJohannes Schindelin via GitGitGadget, May 15, 2025
  32. Jeff KingMay 15, 2025
  33. Junio C HamanoMay 15, 2025
  34. Jeff KingMay 15, 2025
  35. Jeff KingMay 15, 2025
  36. Junio C HamanoMay 15, 2025

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.