Dear GNU tar maintainer(s) / fBSD gtar port maintainer(s),
While trying to use gtar (version 1.22) for backup purposes on FreeBSD 8.0,
because of the listed-incremental option and to maintain compatibility with
non-BSD systems, gtar kept segfaulting for my set of options, specifically
when using --listed-incremental.
Compiling with debug symbols pointed to
incremen.c, line 1532
if (0 < getline (&buf, &bufsize, listed_incremental_stream))
The problem appears to be a difference in getline() behaviour in the fBSD
and GNU libc.
fBSD: The
caller may provide a pointer to a malloc buffer for the line in
*linep,
and the capacity of that buffer in *linecapp; if *linecapp is 0, then
*linep is treated as NULL.
GNU: If *lineptr is NULL, then getline() will allocate a buffer for
storing the line, which
should be freed by the user program. (The value in *n is ignored.)
So fBSD libc looks at the value of linecapp, whereas GNU libc looks at the
value of lineptr, to determine whether to allocate a new buffer or use a
provided one. In the tar source, linecapp (bufsize) is not initialized,
lineptr (buf) is.
The fix is to simply initialize bufsize to 0 as well, to make (line
1232-1233):
char *buf = 0;
size_t bufsize = 0;
This completely fixed the segfaults for me.
Thank you,
Dennis