Coverity fixes upstream from Mark D. Baushke

This commit is contained in:
christos 2006-05-04 15:39:34 +00:00
parent 1468e19297
commit cd037c90cb
9 changed files with 87 additions and 27 deletions

View File

@ -1,3 +1,22 @@
2006-05-04 Mark D. Baushke <mdb@gnu.org>
* filesubr.c (cvs_temp_file): Avoid keeping pointers to free()'d
storage laying around.
* commit.c (commit): Handle possible NULL filename values
returned from cvs_temp_file().
* filesubr.c (cvs_temp_name): Ditto.
* import.c (import): Ditto.
* login.c (password_entry_operation): Ditto.
* logmsg.c (do_verify): Ditto.
* patch.c (patch_fileproc): Ditto.
[Fixes NetBSD coverity cid-2545.]
* buffer.c (packetizing_buffer_output): Initialize outdata.
[Fixes NetBSD coverity cid-2474.]
* server.c (server_updated): Fix NetBSD coverity cid-1352
NetBSD-sparc64 of 2006-May-02 03:02:46.
2005-09-26 Conrad T. Pino <Conrad@Pino.com>
* rcs.c: Use "#ifdef HAVE_FSYNC" just like every where else.

View File

@ -1845,7 +1845,7 @@ packetizing_buffer_output (closure, data, have, wrote)
struct packetizing_buffer *pb = (struct packetizing_buffer *) closure;
char inbuf[BUFFER_DATA_SIZE + 2];
char stack_outbuf[BUFFER_DATA_SIZE + PACKET_SLOP + 4];
struct buffer_data *outdata;
struct buffer_data *outdata = NULL;
char *outbuf;
int size, status, translated;
@ -1900,6 +1900,11 @@ packetizing_buffer_output (closure, data, have, wrote)
buf_output (pb->buf, outbuf, translated + 2);
else
{
/* if ((have + PACKET_SLOP + 4) > BUFFER_DATA_SIZE), then
outdata may be NULL. */
if (outdata == NULL)
abort ();
outdata->size = translated + 2;
buf_append_data (pb->buf, outdata, outdata);
}

View File

@ -642,7 +642,8 @@ commit (argc, argv)
fp = cvs_temp_file (&fname);
if (fp == NULL)
error (1, 0, "cannot create temporary file %s", fname);
error (1, 0, "cannot create temporary file %s",
fname ? fname : "(null)");
if (fwrite (saved_message, 1, strlen (saved_message), fp)
!= strlen (saved_message))
error (1, errno, "cannot write temporary file %s", fname);

View File

@ -733,7 +733,8 @@ cvs_temp_name ()
fp = cvs_temp_file (&fn);
if (fp == NULL)
error (1, errno, "Failed to create temporary file");
error (1, errno, "Failed to create temporary file %s",
fn ? fn : "(null)");
if (fclose (fp) == EOF)
error (0, errno, "Failed to close temporary file %s", fn);
return fn;
@ -770,7 +771,8 @@ cvs_temp_name ()
* NFS locking thing, but until I hear of more problems, I'm not going to
* bother.
*/
FILE *cvs_temp_file (filename)
FILE *
cvs_temp_file (filename)
char **filename;
{
char *fn;
@ -809,7 +811,11 @@ FILE *cvs_temp_file (filename)
errno = save_errno;
}
if (fp == NULL) free (fn);
if (fp == NULL)
{
free (fn);
fn = NULL;
}
/* mkstemp is defined to open mode 0600 using glibc 2.0.7+ */
/* FIXME - configure can probably tell us which version of glibc we are
* linking to and not chmod for 2.0.7+
@ -824,7 +830,11 @@ FILE *cvs_temp_file (filename)
fn = tempnam (Tmpdir, "cvs");
if (fn == NULL) fp = NULL;
else if ((fp = CVS_FOPEN (fn, "w+")) == NULL) free (fn);
else if ((fp = CVS_FOPEN (fn, "w+")) == NULL)
{
free (fn);
fn = NULL;
}
else chmod (fn, 0600);
/* tempnam returns a pointer to a newly malloc'd string, so there's
@ -874,6 +884,11 @@ FILE *cvs_temp_file (filename)
#endif
*filename = fn;
if (fn == NULL && fp != NULL)
{
fclose (fp);
fp = NULL;
}
return fp;
}

View File

@ -317,7 +317,8 @@ import (argc, argv)
/* Create the logfile that will be logged upon completion */
if ((logfp = cvs_temp_file (&tmpfile)) == NULL)
error (1, errno, "cannot create temporary file `%s'", tmpfile);
error (1, errno, "cannot create temporary file `%s'",
tmpfile ? tmpfile : "(null)");
/* On systems where we can unlink an open file, do so, so it will go
away no matter how we exit. FIXME-maybe: Should be checking for
errors but I'm not sure which error(s) we get if we are on a system

View File

@ -387,7 +387,8 @@ process:
/* create and open a temp file */
if ((tmp_fp = cvs_temp_file (&tmp_name)) == NULL)
error (1, errno, "unable to open temp file %s", tmp_name);
error (1, errno, "unable to open temp file %s",
tmp_name ? tmp_name : "(null)");
line = 0;
while ((line_length = getline (&linebuf, &linebuf_len, fp)) >= 0)

View File

@ -441,7 +441,8 @@ do_verify (messagep, repository)
temp file, and close the file. */
if ((fp = cvs_temp_file (&fname)) == NULL)
error (1, errno, "cannot create temporary file %s", fname);
error (1, errno, "cannot create temporary file %s",
fname ? fname : "(null)");
if (*messagep != NULL)
fputs (*messagep, fp);
@ -547,7 +548,7 @@ do_verify (messagep, repository)
if (unlink_file (fname) < 0)
error (0, errno, "cannot remove %s", fname);
free (fname);
free( verifymsg_script );
free (verifymsg_script);
verifymsg_script = NULL;
}

View File

@ -518,7 +518,8 @@ patch_fileproc (callerdat, finfo)
*/
if ((fp1 = cvs_temp_file (&tmpfile1)) == NULL)
{
error (0, errno, "cannot create temporary file %s", tmpfile1);
error (0, errno, "cannot create temporary file %s",
tmpfile1 ? tmpfile1 : "(null)");
ret = 1;
goto out;
}
@ -527,7 +528,8 @@ patch_fileproc (callerdat, finfo)
error (0, errno, "warning: cannot close %s", tmpfile1);
if ((fp2 = cvs_temp_file (&tmpfile2)) == NULL)
{
error (0, errno, "cannot create temporary file %s", tmpfile2);
error (0, errno, "cannot create temporary file %s",
tmpfile2 ? tmpfile2 : "(null)");
ret = 1;
goto out;
}
@ -536,7 +538,8 @@ patch_fileproc (callerdat, finfo)
error (0, errno, "warning: cannot close %s", tmpfile2);
if ((fp3 = cvs_temp_file (&tmpfile3)) == NULL)
{
error (0, errno, "cannot create temporary file %s", tmpfile3);
error (0, errno, "cannot create temporary file %s",
tmpfile3 ? tmpfile3 : "(null)");
ret = 1;
goto out;
}
@ -752,16 +755,28 @@ failed to read diff file header %s for %s: end of file", tmpfile3, rcs);
free (line1);
if (line2)
free (line2);
if (CVS_UNLINK (tmpfile1) < 0)
error (0, errno, "cannot unlink %s", tmpfile1);
if (CVS_UNLINK (tmpfile2) < 0)
error (0, errno, "cannot unlink %s", tmpfile2);
if (CVS_UNLINK (tmpfile3) < 0)
error (0, errno, "cannot unlink %s", tmpfile3);
free (tmpfile1);
free (tmpfile2);
free (tmpfile3);
tmpfile1 = tmpfile2 = tmpfile3 = NULL;
if (tmpfile1 != NULL)
{
if (CVS_UNLINK (tmpfile1) < 0)
error (0, errno, "cannot unlink %s", tmpfile1);
free (tmpfile1);
tmpfile1 = NULL;
}
if (tmpfile2 != NULL)
{
if (CVS_UNLINK (tmpfile2) < 0)
error (0, errno, "cannot unlink %s", tmpfile2);
free (tmpfile2);
tmpfile2 = NULL;
}
if (tmpfile3 != NULL)
{
if (CVS_UNLINK (tmpfile3) < 0)
error (0, errno, "cannot unlink %s", tmpfile3);
free (tmpfile3);
tmpfile3 = NULL;
}
if (dargc)
{
run_arg_free_p (dargc, dargv);

View File

@ -4218,7 +4218,6 @@ CVS server internal error: no mode in server_updated");
if (updated == SERVER_UPDATED)
{
Node *node;
Entnode *entnode;
if (!(supported_response ("Created")
&& supported_response ("Update-existing")))
@ -4236,9 +4235,12 @@ CVS server internal error: no mode in server_updated");
in case we end up processing it again (e.g. modules3-6
in the testsuite). */
node = findnode_fn (finfo->entries, finfo->file);
entnode = node->data;
free (entnode->timestamp);
entnode->timestamp = xstrdup ("=");
if (node != NULL)
{
Entnode *entnode = node->data;
free (entnode->timestamp);
entnode->timestamp = xstrdup ("=");
}
}
else if (updated == SERVER_MERGED)
buf_output0 (protocol, "Merged ");