diff --git a/src/ChangeLog b/src/ChangeLog index 421bf321a..47f0e3082 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2002-11-13 Pavel Roskin + * man2hlp.c (persistent_fread): Return error for len <= 0. + (persistent_fwrite): Likewise. + (main): Check the result of the second ftell(). + * cmd.h: Fully exclude WPanel from public interfaces of cmd.c. * cmd.c: All commands operate on current panels. (get_a_panel): Remove. diff --git a/src/man2hlp.c b/src/man2hlp.c index cca2df845..078b6547f 100644 --- a/src/man2hlp.c +++ b/src/man2hlp.c @@ -74,6 +74,9 @@ persistent_fread (void *data, size_t len, FILE *stream) size_t bytes_done = 0; char *ptr = (char *) data; + if (len <= 0) + return 0; + while (bytes_done < len) { count = len - bytes_done; if (count > MAX_STREAM_BLOCK) @@ -102,6 +105,9 @@ persistent_fwrite (const void *data, size_t len, FILE *stream) size_t bytes_done = 0; const char *ptr = (const char *) data; + if (len <= 0) + return 0; + while (bytes_done < len) { count = len - bytes_done; if (count > MAX_STREAM_BLOCK) @@ -780,6 +786,11 @@ main (int argc, char **argv) } cont_start = ftell (f_out); + if (cont_start <= 0) { + perror (c_out); + return 1; + } + if (topics) fprintf (f_out, "\004[Contents]\n%s\n\n", topics); else @@ -830,7 +841,9 @@ main (int argc, char **argv) } file_end = ftell (f_out); - if (file_end <= 0) { + + /* Sanity check */ + if ((file_end <= 0) || (file_end - cont_start <= 0)) { perror (c_out); return 1; }