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

Re: [PATCH] Add git-imap-send.

From
MWMark Wooding <mdw@distorted.org.uk>
Date
Mar 9, 2006, 13:26 UTC
Message-ID
<slrne10b8c.fr9.mdw@metalzone.distorted.org.uk>
In-Reply-To
<Pine.LNX.4.63.0603091243001.20908@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Sorry, I was unclear. Of course, memcmp() does not stop on NUL. But it 
> stops when that NUL is different from what the other pointer has. Which is 
> the case here.

Does it really? My copy of the spec doesn't say that. It says only this:

: 7.21.4.1 The memcmp function : : Synopsis : : #include <string.h> : int memcmp(const void *s1, const void *s2, size_t n); : : Description : : The memcmp() function compares the first n characters of the object : pointed to by s1 to the first n characters of the object pointed to by : s2.262) : : Returns : : The memcmp function returns an integer greater than, equal to, or less : than zero, accordingly as the object pointed to by s1 is greater than, : equal to, or less than the object pointed to by s2. : : 262) The contents of ``holes'' used as padding for purposes of : alignment within structure objects are indeterminate. Strings shorter : than their allocated space and unions may also cause problems in : comparison.

There are reasons for which it'd be desirable that memcmp really compare all the bytes, even if it can in theory stop early: in particular, there are cases where early exit can leak timing information which makes it possible to attack cryptographic protocols.

I'd have to recommend strncmp for this job.
-- [mdw]
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 6 of 13 in “Add git-imap-send.”
  1. Add git-imap-send.Mike McCormack, Mar 6, 2006
  2. Junio C HamanoMar 9, 2006
  3. Johannes SchindelinMar 9, 2006
  4. Andreas EricssonMar 9, 2006
  5. Johannes SchindelinMar 9, 2006
  6. Mark WoodingMar 9, 2006
  7. Johannes SchindelinMar 9, 2006
  8. Mark WoodingMar 10, 2006
  9. Linus TorvaldsMar 9, 2006
  10. Junio C HamanoMar 9, 2006
  11. Linus TorvaldsMar 9, 2006
  12. Junio C HamanoMar 9, 2006
  13. Mike McCormackMar 10, 2006

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.