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

Re: [PATCH v2] sha1_name: fix uninitialized memory errors

From
Jeff King <peff@peff.net>
Date
Feb 27, 2018, 21:33 UTC
Message-ID
<20180227213305.GB6899@sigill.intra.peff.net>
In-Reply-To
<20180227114704.193145-1-dstolee@microsoft.com>
On Tue, Feb 27, 2018 at 06:47:04AM -0500, Derrick Stolee wrote:
Show 17 quoted lines
> Peff made an excellent point about the nested if statements. This
> goes back to Christian's original recommendation.
> 
> -- >8 --
> 
> During abbreviation checks, we navigate to the position within a
> pack-index that an OID would be inserted and check surrounding OIDs
> for the maximum matching prefix. This position may be beyond the
> last position, because the given OID is lexicographically larger
> than every OID in the pack. Then nth_packed_object_oid() does not
> initialize "oid".
> 
> Use the return value of nth_packed_object_oid() to prevent these
> errors.
> 
> Reported-by: Christian Couder <christian.couder@gmail.com>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Thanks, this looks good to me.

Semi-related, I wondered also at the weird asymmetry in the if-else, which is:

  if ...
  else if ...
  if ...

but the comment directly above says: "we consider a maximum of three objects nearby". I think it's actually two, because you can only trigger one of the first two conditionals.

Is that right?

Let's imagine we're looking for object 1234abcd. If we didn't find a match, then we might have:

  1234abcc 
  1234abce <-- first points here
in which case we need to check both first-1 and first. And we do.
If we do have a match, then we might see:
  1234abcc
  1234abcd <-- first points here
  1234abce
and we must check first-1 and first+1, but _not_ first.
So I think the code is right, but the comment is wrong.
-Peff
Previous: Derrick StoleeNext: Junio C Hamano
Message 9 of 14 in “Use of uninitialised value of size 8 in sha1_name.c”
  1. Christian CouderFeb 26, 2018
  2. Jeff KingFeb 26, 2018
  3. Christian CouderFeb 26, 2018
  4. Derrick StoleeFeb 26, 2018
  5. Christian CouderFeb 26, 2018
  6. sha1_name: fix uninitialized memory errorsDerrick Stolee, Feb 26, 2018
  7. Jeff KingFeb 26, 2018
  8. sha1_name: fix uninitialized memory errorsDerrick Stolee, Feb 27, 2018
  9. Jeff KingFeb 27, 2018
  10. Junio C HamanoFeb 27, 2018
  11. Jeff KingFeb 27, 2018
  12. Junio C HamanoFeb 28, 2018
  13. Derrick StoleeFeb 28, 2018
  14. Junio C HamanoFeb 28, 2018

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.