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

[PATCH 0/3] Auditing use of xwrite()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 2, 2024, 19:03 UTC
Message-ID
<20240302190348.3946569-1-gitster@pobox.com>

The xwrite() helper relieves us from having to worry about an interrupted write(2) system call that returns an EINTR error without writing any, in which case we need to retry the system call. It, just as the underlying write(2) system call, however can return without writing the bytes requested to be written fully. A code that uses xwrite() and wants to write the full contents of the buffer needs to take care of such a "short write" situation, typically by calling xwrite() in a loop.

We recently audited all the calls to xwrite(), and have found two classes of potential "problems". This miniseries is about fixing them.

 * There are such loops around xwrite() as described above, which
   were written long time ago.  The write_in_full() helper does
   implement such a loop in a reusable way, and we should just call
   it instead.
 * There are xwrite() calls whose return value is ignored.  We would
   not be able to detect (and complete) "short write" in such callers,
   of course, but more importantly, we would not notice I/O failures.
   Again, use write_in_full() to deal with short writes, and check
   the return value from it to detect errors.
Junio C Hamano (3):
  unpack: rewrite hand-rolled loop of xwrite()s with write_in_full()
  sideband: avoid short write(2)
  repack: check error writing to pack-objects subprocess
 builtin/index-pack.c     | 17 +++--------------
 builtin/repack.c         |  5 +++--
 builtin/unpack-objects.c |  8 +-------
 sideband.c               |  4 ++--
 4 files changed, 9 insertions(+), 25 deletions(-)
-- 
2.44.0-84-gb387623c12
Next: Junio C Hamano
Message 1 of 7 in “Auditing use of xwrite()”
  1. 0/3 Auditing use of xwrite()Junio C Hamano, Mar 2, 2024
  2. 1/3 unpack: replace xwrite() loop with write_in_full()Junio C Hamano, Mar 2, 2024
  3. Patrick SteinhardtMar 4, 2024
  4. Junio C HamanoMar 4, 2024
  5. Junio C HamanoMar 4, 2024
  6. 3/3 repack: check error writing to pack-objects subprocessJunio C Hamano, Mar 2, 2024
  7. 2/3 sideband: avoid short write(2)Junio C Hamano, Mar 2, 2024

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.