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

Re: unchecked uses of strdup

From
Alex Riesen <raa.lkml@gmail.com>
Date
Apr 6, 2006, 14:11 UTC
Message-ID
<81b0412b0604060711o57fb110cm5fa559c0fd785a66@mail.gmail.com>
In-Reply-To
<87d5fwau3z.fsf_-_@rho.meyering.net>
On 4/5/06, Jim Meyering <jim@meyering.net> wrote:
Show 12 quoted lines
> There are pretty many uses of strdup in git's sources.
> Here's one that can cause trouble if it ever returns NULL:
>
>     [from fsck-objects.c]
>     static int fsck_head_link(void)
>     {
>             unsigned char sha1[20];
>             const char *git_HEAD = strdup(git_path("HEAD"));
>             const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 1);
>
> The problem is that resolve_ref does an unconditional `stat'
> on the parameter corresponding to the maybe-NULL git_HEAD.

That's actually alright (aside a nice core file). Worse are the cases where a NULL would cause some "normal" behaviour, e.g. arguments, which have a meaning for NULL value.

Previous: Jim MeyeringNext: Pavel Roskin
Message 6 of 11 in “Add git-clean command”
  1. Add git-clean commandPavel Roskin, Apr 3, 2006
  2. Junio C HamanoApr 4, 2006
  3. Sam RavnborgApr 4, 2006
  4. Pavel RoskinApr 4, 2006
  5. unchecked uses of strdupJim Meyering, Apr 5, 2006
  6. Alex RiesenApr 6, 2006
  7. Pavel RoskinApr 5, 2006
  8. Martin WaitzApr 4, 2006
  9. Junio C HamanoApr 4, 2006
  10. Alex RiesenApr 4, 2006
  11. Pavel RoskinApr 4, 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.