getline(3): Fix segfault caused by NULL pointer
authorJohn Marino <netbsd@marino.st>
Wed, 7 Nov 2012 20:15:35 +0000 (21:15 +0100)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Wed, 7 Nov 2012 22:31:45 +0000 (23:31 +0100)
commit50b19aeb57b413e29e1eff28311433ea7d78f4a3
treed23c3e81e8379d48927b3629d6ed31ff0e70f2dd
parent148e9c0bc3408f258f158bf6fb40ab19ce200cf0
getline(3): Fix segfault caused by NULL pointer

This fixes a segfault seen with pkg's audit function, and effectively syncs
getdelim with FreeBSD.

Taken-from: FreeBSD SVN 197752 (04 OCT 2009)

- Tolerate applications that pass a NULL pointer for the buffer and
  claim that the capacity of the buffer is nonzero.

- If an application passes in a non-NULL buffer pointer and claims the
  buffer has zero capacity, we should free (well, realloc) it anyway.
  It could have been obtained from malloc(0), so failing to free it
  would be a small memory leak.
lib/libc/stdio/getdelim.c