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

Re: [PATCH 1/7] cleanups: Fix resource leak and buffer overrun in daemon.c

From
Junio C Hamano <junkio@cox.net>
Date
Apr 17, 2006, 21:42 UTC
Message-ID
<7vu08rkhey.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060417151447.D4FE619B90E@sergelap.hallyn.com>
"Serge E. Hallyn" <serue@us.ibm.com> writes:
> Address two reports from an automatic code analyzer:
>
> 1. In logreport, it is possible to write \0 one
> character past the end of buf[].

I am perhaps slower than I usually am today, but it seems to me that the code caps msglen to (maxlen-1) and then adds that to buflen.

Now, maxlen is (sizeof(buf)-buflen-1), so that means after the "buflen += msglen" happens, buflen is at most:

	buflen + (sizeof(buf)-buflen-1) - 1
        = sizeof(buf) - 2

And then "buf[buflen++] = '\n'; buf[buflen] = '\0'" happens. '\n' is written at sizeof(buf)-2 (or lower index than that) and '\0' is written at sizeof(buf)-1 (or lower). I am unsure how it steps beyond the end...

> 2. In socksetup, socklist can be leaked when returning
> if set_reuse_addr().  Note: dunno why this case returns...

I am not sure why this part returns either. It appears to me that it should just keep going just like the cases where bind/listen fails.

Previous: Serge E. HallynNext: Serge E. Hallyn
Message 3 of 13 in “cleanups: intro”
  1. 0/7 cleanups: introSerge E. Hallyn, Apr 17, 2006
  2. 1/7 cleanups: Fix resource leak and buffer overrun in daemon.cSerge E. Hallyn, Apr 17, 2006
  3. Junio C HamanoApr 17, 2006
  4. Serge E. HallynApr 18, 2006
  5. Junio C HamanoApr 18, 2006
  6. 2/7 cleanups: Fix potential bugs in connect.cSerge E. Hallyn, Apr 17, 2006
  7. 3/7 cleanups: Remove unused vars from combine-diff.cSerge E. Hallyn, Apr 17, 2006
  8. 5/7 cleanups: Remove unused variable from sha1_file.cSerge E. Hallyn, Apr 17, 2006
  9. Junio C HamanoApr 17, 2006
  10. 6/7 cleanups: prevent leak of two strduped strings in config.cSerge E. Hallyn, Apr 17, 2006
  11. 4/7 cleanups: Remove impossible case in quote.cSerge E. Hallyn, Apr 17, 2006
  12. 7/7 cleanups: remove unused variable from exec_cmd.cSerge E. Hallyn, Apr 17, 2006
  13. Junio C HamanoApr 17, 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.