mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
Fix Coverity issues
* src/ftp.c (getftp): on error, close the file and attempt to remove it before exiting. * src/hsts.c (hsts_store_open): update modification time in the end.
This commit is contained in:
parent
30b0705fa6
commit
160f0e908f
16
src/ftp.c
16
src/ftp.c
@ -321,7 +321,8 @@ getftp (struct url *u, wgint passed_expected_bytes, wgint *qtyread,
|
|||||||
{
|
{
|
||||||
int csock, dtsock, local_sock, res;
|
int csock, dtsock, local_sock, res;
|
||||||
uerr_t err = RETROK; /* appease the compiler */
|
uerr_t err = RETROK; /* appease the compiler */
|
||||||
FILE *fp;
|
FILE *fp = NULL;
|
||||||
|
struct_fstat st;
|
||||||
char *respline, *tms;
|
char *respline, *tms;
|
||||||
const char *user, *passwd, *tmrate;
|
const char *user, *passwd, *tmrate;
|
||||||
int cmd = con->cmd;
|
int cmd = con->cmd;
|
||||||
@ -1514,8 +1515,9 @@ Error in server response, closing control connection.\n"));
|
|||||||
{
|
{
|
||||||
fd_close (csock);
|
fd_close (csock);
|
||||||
fd_close (dtsock);
|
fd_close (dtsock);
|
||||||
|
err = CONERROR;
|
||||||
logputs (LOG_NOTQUIET, "Could not perform SSL handshake.\n");
|
logputs (LOG_NOTQUIET, "Could not perform SSL handshake.\n");
|
||||||
return CONERROR;
|
goto exit_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1525,7 +1527,8 @@ Error in server response, closing control connection.\n"));
|
|||||||
{
|
{
|
||||||
fd_close (csock);
|
fd_close (csock);
|
||||||
fd_close (dtsock);
|
fd_close (dtsock);
|
||||||
return CONERROR;
|
err = CONERROR;
|
||||||
|
goto exit_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1762,6 +1765,13 @@ Error in server response, closing control connection.\n"));
|
|||||||
}
|
}
|
||||||
} while (try_again);
|
} while (try_again);
|
||||||
return RETRFINISHED;
|
return RETRFINISHED;
|
||||||
|
|
||||||
|
exit_error:
|
||||||
|
|
||||||
|
/* If fp is a regular file, close and try to remove it */
|
||||||
|
if (fp && !output_stream)
|
||||||
|
fclose (fp);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A one-file FTP loop. This is the part where FTP retrieval is
|
/* A one-file FTP loop. This is the part where FTP retrieval is
|
||||||
|
16
src/hsts.c
16
src/hsts.c
@ -464,7 +464,7 @@ hsts_store_t
|
|||||||
hsts_store_open (const char *filename)
|
hsts_store_open (const char *filename)
|
||||||
{
|
{
|
||||||
hsts_store_t store = NULL;
|
hsts_store_t store = NULL;
|
||||||
struct stat st;
|
struct_stat st;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
store = xnew0 (struct hsts_store);
|
store = xnew0 (struct hsts_store);
|
||||||
@ -473,27 +473,29 @@ hsts_store_open (const char *filename)
|
|||||||
|
|
||||||
if (file_exists_p (filename))
|
if (file_exists_p (filename))
|
||||||
{
|
{
|
||||||
if (stat (filename, &st) == 0)
|
|
||||||
store->last_mtime = st.st_mtime;
|
|
||||||
|
|
||||||
fp = fopen (filename, "r");
|
fp = fopen (filename, "r");
|
||||||
|
|
||||||
if (!fp || !hsts_read_database (store, fp, false))
|
if (!fp || !hsts_read_database (store, fp, false))
|
||||||
{
|
{
|
||||||
/* abort! */
|
/* abort! */
|
||||||
hsts_store_close (store);
|
hsts_store_close (store);
|
||||||
xfree (store);
|
xfree (store);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
if (fp)
|
|
||||||
fclose (fp);
|
if (fstat (fileno (fp), &st) == 0)
|
||||||
|
store->last_mtime = st.st_mtime;
|
||||||
|
fclose (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hsts_store_save (hsts_store_t store, const char *filename)
|
hsts_store_save (hsts_store_t store, const char *filename)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct_stat st;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user