mirror of
https://github.com/mirror/wget.git
synced 2025-01-07 19:00:30 +08:00
[svn] Don't abort in read_whole_lines when a line begins with \0.
Published in <sxsu1v5nrtg.fsf@florida.arsdigita.de>.
This commit is contained in:
parent
8a2ab60263
commit
b248bfe395
@ -1,3 +1,7 @@
|
|||||||
|
2001-12-06 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
|
* utils.c (read_whole_line): Handle lines beginning with \0.
|
||||||
|
|
||||||
2001-12-05 Hrvoje Niksic <hniksic@arsdigita.com>
|
2001-12-05 Hrvoje Niksic <hniksic@arsdigita.com>
|
||||||
|
|
||||||
* recur.c (convert_all_links): Guard against duplicates in
|
* recur.c (convert_all_links): Guard against duplicates in
|
||||||
|
17
src/utils.c
17
src/utils.c
@ -955,13 +955,17 @@ suffix (const char *str)
|
|||||||
|
|
||||||
/* Read a line from FP. The function reallocs the storage as needed
|
/* Read a line from FP. The function reallocs the storage as needed
|
||||||
to accomodate for any length of the line. Reallocs are done
|
to accomodate for any length of the line. Reallocs are done
|
||||||
storage exponentially, doubling the storage after each overflow to
|
exponentially, doubling the storage after each overflow to minimize
|
||||||
minimize the number of calls to realloc() and fgets(). The newline
|
the number of calls to realloc() and fgets(). The newline
|
||||||
character at the end of line is retained.
|
character at the end of line is retained.
|
||||||
|
|
||||||
After end-of-file is encountered without anything being read, NULL
|
After end-of-file is encountered without anything being read, NULL
|
||||||
is returned. NULL is also returned on error. To distinguish
|
is returned. NULL is also returned on error. To distinguish
|
||||||
between these two cases, use the stdio function ferror(). */
|
between these two cases, use the stdio function ferror().
|
||||||
|
|
||||||
|
A future version of this function will be rewritten to use fread()
|
||||||
|
instead of fgets(), and to return the length of the line, which
|
||||||
|
will make the function usable on files with binary content. */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
read_whole_line (FILE *fp)
|
read_whole_line (FILE *fp)
|
||||||
@ -973,9 +977,14 @@ read_whole_line (FILE *fp)
|
|||||||
while (fgets (line + length, bufsize - length, fp))
|
while (fgets (line + length, bufsize - length, fp))
|
||||||
{
|
{
|
||||||
length += strlen (line + length);
|
length += strlen (line + length);
|
||||||
assert (length > 0);
|
if (length == 0)
|
||||||
|
/* Possible for example when reading from a binary file where
|
||||||
|
a line begins with \0. */
|
||||||
|
continue;
|
||||||
|
|
||||||
if (line[length - 1] == '\n')
|
if (line[length - 1] == '\n')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* fgets() guarantees to read the whole line, or to use up the
|
/* fgets() guarantees to read the whole line, or to use up the
|
||||||
space we've given it. We can double the buffer
|
space we've given it. We can double the buffer
|
||||||
unconditionally. */
|
unconditionally. */
|
||||||
|
Loading…
Reference in New Issue
Block a user