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

Re: [PATCH v3] refs: fix uninitialized memory access of `max_index`

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jan 24, 2025, 15:48 UTC
Message-ID
<CAOLa=ZR=Hz+LU0n-uC2dpk8_sLqAyaxO0NswJH8bP_kEdDdbUQ@mail.gmail.com>
In-Reply-To
<Z5On1waE-2uwIjS2@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 44 quoted lines
> On Fri, Jan 24, 2025 at 03:02:03PM +0100, Karthik Nayak wrote:
>> When migrating reflogs between reference backends, maintaining the
>> original order of the reflog entries is crucial. To achieve this, an
>> `index` field is stored within the `ref_update` struct.
>>
>> In the reftable backend, before writing any references, the writer must
>> be configured with the minimum and maximum update index values. The
>> `max_update_index` is derived from the maximum `ref_update.index` value
>> in a transaction . The commit bc67b4ab5f (reftable: write correct
>> max_update_index to header, 2025-01-15) addressed this by propagating the
>> `max_update_index` value from the transaction to
>> `write_transaction_table_arg` and, ultimately, to
>> `reftable_writer_set_limits()`, which sets the min and max index for the
>> reftable writer.
>>
>> However, that commit introduced an issue:
>>
>>   - In `reftable_transaction_data`, which contains an array of
>>   `write_transaction_table_arg`, only the first element was assigned the
>>   `max_index` value.
>>
>> As a result, any elements beyond the first in the array contained
>> uninitialized `max_index`. The writer contains multiple elements of
>> `write_transaction_table_arg` to correspond to different worktrees being
>> written. This uninitialized value was later used to set the
>> `max_update_index` for the writer, potentially causing overflow or
>> undefined behavior.
>
> It reads a bit funny as a bulleted list with a single item, only. A
> suggestion for the above:
>
>     However, we only set the update index for the first
>     `write_transaction_table_arg`, even though there can be multiple
>     such arguments. This is the case when we write to multiple stacks in
>     a single transaction, e.g. when updating references in two different
>     worktrees at once. And, if so, we wouldn't have initialized the
>     update index for any but the first such argument. This uninitialized
>     value was later used to set the `max_update_index` for the writer,
>     potentially causing undefined behaviour.
>
> Other than that this is nicely described, and the fix looks reasonable,
> too.
>
> Patrick

Thanks Patrick for taking the time, this seems much better. Let me add this in for the next version.

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 17 of 21 in “Bug in 2.48 with `git refs migrate`”
  1. brian m. carlsonJan 13, 2025
  2. Patrick SteinhardtJan 13, 2025
  3. Karthik NayakJan 15, 2025
  4. Junio C HamanoJan 15, 2025
  5. Karthik NayakJan 16, 2025
  6. brian m. carlsonJan 16, 2025
  7. Karthik NayakJan 16, 2025
  8. brian m. carlsonJan 16, 2025
  9. Junio C HamanoJan 17, 2025
  10. Karthik NayakJan 17, 2025
  11. Karthik NayakJan 17, 2025
  12. reftable: write correct max_update_index to headerKarthik Nayak, Jan 23, 2025
  13. Junio C HamanoJan 23, 2025
  14. Junio C HamanoJan 23, 2025
  15. refs: fix uninitialized memory access of `max_index`Karthik Nayak, Jan 24, 2025
  16. Patrick SteinhardtJan 24, 2025
  17. Karthik NayakJan 24, 2025
  18. Patrick SteinhardtJan 27, 2025
  19. Junio C HamanoJan 27, 2025
  20. Karthik NayakJan 24, 2025
  21. Junio C HamanoJan 24, 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.