unchecked uses of strdup
- From
Jim Meyering <jim@meyering.net>
- Date
- Apr 5, 2006, 16:02 UTC
- Message-ID
- <87d5fwau3z.fsf_-_@rho.meyering.net>
- In-Reply-To
- <1144165927.30675.32.camel@dv>
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.
One solution is to change such uses of strdup to uses of xstrdup.