mirror of
https://github.com/mirror/wget.git
synced 2025-01-18 08:10:42 +08:00
Fix double fclose() with -d while fuzzing
* src/ftp.c (ftp_loop_internal): Set warc_tmp to NULL after ffclose() * src/init.c (cleanup): Set output_stream to NULL after fclose() * src/log.c (log_close): Set global stream vars to NULL after closing * src/recur.c (retrieve_tree): Set rejectedlog to NULL after closing * src/warc.c (warc_close): Set stream vars to NULL after closing
This commit is contained in:
parent
eaf167aaaa
commit
3ceb6e5630
@ -1982,7 +1982,10 @@ ftp_loop_internal (struct url *u, struct url *original_url, struct fileinfo *f,
|
|||||||
#endif
|
#endif
|
||||||
/* Fatal errors, give up. */
|
/* Fatal errors, give up. */
|
||||||
if (warc_tmp != NULL)
|
if (warc_tmp != NULL)
|
||||||
|
{
|
||||||
fclose (warc_tmp);
|
fclose (warc_tmp);
|
||||||
|
warc_tmp = NULL;
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR:
|
case CONSOCKERR: case CONERROR: case FTPSRVERR: case FTPRERR:
|
||||||
case WRITEFAILED: case FTPUNKNOWNTYPE: case FTPSYSERR:
|
case WRITEFAILED: case FTPUNKNOWNTYPE: case FTPSYSERR:
|
||||||
@ -2110,7 +2113,10 @@ Removing file due to --delete-after in ftp_loop_internal():\n"));
|
|||||||
*local_file = xstrdup (locf);
|
*local_file = xstrdup (locf);
|
||||||
|
|
||||||
if (warc_tmp != NULL)
|
if (warc_tmp != NULL)
|
||||||
fclose (warc_tmp);
|
{
|
||||||
|
fclose (warc_tmp);
|
||||||
|
warc_tmp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return RETROK;
|
return RETROK;
|
||||||
} while (!opt.ntry || (count < opt.ntry));
|
} while (!opt.ntry || (count < opt.ntry));
|
||||||
|
@ -1900,11 +1900,12 @@ cleanup (void)
|
|||||||
|
|
||||||
log_close ();
|
log_close ();
|
||||||
|
|
||||||
if (output_stream)
|
if (output_stream && output_stream != stderr)
|
||||||
{
|
{
|
||||||
if (fclose (output_stream) == EOF)
|
FILE *fp = output_stream;
|
||||||
inform_exit_status (CLOSEFAILED);
|
|
||||||
output_stream = NULL;
|
output_stream = NULL;
|
||||||
|
if (fclose (fp) == EOF)
|
||||||
|
inform_exit_status (CLOSEFAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No need to check for error because Wget flushes its output (and
|
/* No need to check for error because Wget flushes its output (and
|
||||||
|
11
src/log.c
11
src/log.c
@ -676,9 +676,16 @@ log_close (void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (logfp && (logfp != stderr))
|
if (logfp && logfp != stderr && logfp != stdout)
|
||||||
fclose (logfp);
|
{
|
||||||
|
if (logfp == stdlogfp)
|
||||||
|
stdlogfp = NULL;
|
||||||
|
if (logfp == filelogfp)
|
||||||
|
filelogfp = NULL;
|
||||||
|
fclose (logfp);
|
||||||
|
}
|
||||||
logfp = NULL;
|
logfp = NULL;
|
||||||
|
|
||||||
inhibit_logging = true;
|
inhibit_logging = true;
|
||||||
save_context_p = false;
|
save_context_p = false;
|
||||||
|
|
||||||
|
@ -524,7 +524,10 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rejectedlog)
|
if (rejectedlog)
|
||||||
fclose (rejectedlog);
|
{
|
||||||
|
fclose (rejectedlog);
|
||||||
|
rejectedlog = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* If anything is left of the queue due to a premature exit, free it
|
/* If anything is left of the queue due to a premature exit, free it
|
||||||
now. */
|
now. */
|
||||||
|
@ -1240,9 +1240,15 @@ warc_close (void)
|
|||||||
warc_write_metadata ();
|
warc_write_metadata ();
|
||||||
*warc_current_warcinfo_uuid_str = 0;
|
*warc_current_warcinfo_uuid_str = 0;
|
||||||
fclose (warc_current_file);
|
fclose (warc_current_file);
|
||||||
|
warc_current_file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warc_current_cdx_file != NULL)
|
if (warc_current_cdx_file != NULL)
|
||||||
fclose (warc_current_cdx_file);
|
{
|
||||||
|
fclose (warc_current_cdx_file);
|
||||||
|
warc_current_cdx_file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (warc_log_fp != NULL)
|
if (warc_log_fp != NULL)
|
||||||
{
|
{
|
||||||
fclose (warc_log_fp);
|
fclose (warc_log_fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user