Blame SOURCES/mailx-12.5-coverity.patch

580d49
diff --git a/aux.c b/aux.c
580d49
index e51a19a..2733787 100644
580d49
--- a/aux.c
580d49
+++ b/aux.c
580d49
@@ -904,7 +904,7 @@ getrandstring(size_t length)
580d49
 			data[i] = (int)(255 * (rand() / (RAND_MAX + 1.0))) ^
580d49
 				nodedigest[i % sizeof nodedigest];
580d49
 	}
580d49
-	if (fd > 0)
580d49
+	if (fd >= 0)
580d49
 		close(fd);
580d49
 	cp = memtob64(data, length);
580d49
 	rp = salloc(length+1);
580d49
diff --git a/cache.c b/cache.c
580d49
index 9cf7587..a71b019 100644
580d49
--- a/cache.c
580d49
+++ b/cache.c
580d49
@@ -588,6 +588,7 @@ cache_setptr(int transparent)
580d49
 		message[i].m_uid = contents[i];
580d49
 		getcache1(&mb, &message[i], NEED_UNSPEC, 3);
580d49
 	}
580d49
+	free(contents);
580d49
 	ok = OKAY;
580d49
 	if (ok == OKAY) {
580d49
 		mb.mb_type = MB_CACHE;
580d49
diff --git a/cmd3.c b/cmd3.c
580d49
index cb19e2b..2a5ea68 100644
580d49
--- a/cmd3.c
580d49
+++ b/cmd3.c
580d49
@@ -835,7 +835,7 @@ cfile(void *v)
580d49
 		newfileinfo();
580d49
 		return 0;
580d49
 	}
580d49
-	strncpy(mboxname, expand("&"), sizeof mboxname)[sizeof mboxname-1]='\0';
580d49
+	strncpy(mboxname, expand("&"), sizeof mboxname-1)[sizeof mboxname-1]='\0';
580d49
 	return file1(*argv);
580d49
 }
580d49
 
580d49
@@ -1344,7 +1344,7 @@ account(void *v)
580d49
 			a->ac_name = NULL;
580d49
 		return define1(args[0], 1);
580d49
 	}
580d49
-	strncpy(mboxname, expand("&"), sizeof mboxname)[sizeof mboxname-1]='\0';
580d49
+	strncpy(mboxname, expand("&"), sizeof mboxname-1)[sizeof mboxname-1]='\0';
580d49
 	oqf = savequitflags();
580d49
 	if ((a = get_oldaccount(args[0])) == NULL) {
580d49
 		if (args[1]) {
580d49
diff --git a/collect.c b/collect.c
580d49
index 953ae07..949fd32 100644
580d49
--- a/collect.c
580d49
+++ b/collect.c
580d49
@@ -902,6 +902,11 @@ cont:
580d49
 	}
580d49
 	goto out;
580d49
 err:
580d49
+	if (linebuf != NULL) {
580d49
+		free(linebuf);
580d49
+		linebuf = NULL;
580d49
+	}
580d49
+
580d49
 	if (collf != NULL) {
580d49
 		Fclose(collf);
580d49
 		collf = NULL;
580d49
@@ -909,6 +914,9 @@ err:
580d49
         exit(1);
580d49
     }
580d49
 out:
580d49
+	if (linebuf != NULL)
580d49
+		free(linebuf);
580d49
+
580d49
 	if (collf != NULL) {
580d49
 		if ((cp = value("MAILX_TAIL")) != NULL) {
580d49
 			if (is_a_tty[0])
580d49
diff --git a/imap.c b/imap.c
580d49
index 66e0a6b..28b5e22 100644
580d49
--- a/imap.c
580d49
+++ b/imap.c
580d49
@@ -1181,8 +1181,10 @@ imap_setfile1(const char *xserver, int newmail, int isedit, int transparent)
580d49
 	if (!same_imap_account) {
580d49
 		if (!disconnected(account) &&
580d49
 				sopen(sp, &so, use_ssl, uhp,
580d49
-				use_ssl ? "imaps" : "imap", verbose) != OKAY)
580d49
-		return -1;
580d49
+				use_ssl ? "imaps" : "imap", verbose) != OKAY) {
580d49
+			free(account);
580d49
+			return -1;
580d49
+		}
580d49
 	} else
580d49
 		so = mb.mb_sock;
580d49
 	if (!transparent)
580d49
diff --git a/macro.c b/macro.c
580d49
index 741343b..6aba6aa 100644
580d49
--- a/macro.c
580d49
+++ b/macro.c
580d49
@@ -128,6 +128,7 @@ define1(const char *name, int account)
580d49
 					mp->ma_name);
580d49
 			if (sourcing)
580d49
 				unstack();
580d49
+			freelines(lst);
580d49
 			free(mp->ma_name);
580d49
 			free(mp);
580d49
 			return 1;
580d49
diff --git a/main.c b/main.c
580d49
index 573ec9c..f7612a5 100644
580d49
--- a/main.c
580d49
+++ b/main.c
580d49
@@ -462,7 +462,7 @@ usage:
580d49
 		 */
580d49
 		if ((cp = value("folder")) != NULL &&
580d49
 				which_protocol(cp) == PROTO_IMAP)
580d49
-			strncpy(mailname, cp, PATHSIZE)[PATHSIZE-1] = '\0';
580d49
+			strncpy(mailname, cp, PATHSIZE-1)[PATHSIZE-1] = '\0';
580d49
 	}
580d49
 	i = setfile(ef, 0);
580d49
 	if (i < 0)
580d49
@@ -500,7 +500,7 @@ usage:
580d49
 		safe_signal(SIGINT, SIG_IGN);
580d49
 		safe_signal(SIGQUIT, SIG_IGN);
580d49
 	}
580d49
-	strncpy(mboxname, expand("&"), sizeof mboxname)[sizeof mboxname-1]='\0';
580d49
+	strncpy(mboxname, expand("&"), sizeof mboxname-1)[sizeof mboxname-1]='\0';
580d49
 	quit();
580d49
 	return exit_status;
580d49
 }
580d49
diff --git a/popen.c b/popen.c
580d49
index 348fd1e..9520b41 100644
580d49
--- a/popen.c
580d49
+++ b/popen.c
580d49
@@ -246,9 +246,11 @@ Zopen(const char *file, const char *mode, int *compression)
580d49
 open:	if ((output = Ftemp(&tempfn, "Rz", "w+", 0600, 0)) == NULL) {
580d49
 		perror(catgets(catd, CATSET, 167, "tmpfile"));
580d49
 		close(input);
580d49
+		Ftfree(&tempfn);
580d49
 		return NULL;
580d49
 	}
580d49
 	unlink(tempfn);
580d49
+	Ftfree(&tempfn);
580d49
 	if (input >= 0 || (*compression&FP_MASK) == FP_IMAP ||
580d49
 			(*compression&FP_MASK) == FP_MAILDIR) {
580d49
 		if (decompress(*compression, input, fileno(output)) < 0) {
580d49
diff --git a/quit.c b/quit.c
580d49
index f70aec2..1827516 100644
580d49
--- a/quit.c
580d49
+++ b/quit.c
580d49
@@ -141,7 +141,7 @@ quit(void)
580d49
 	FILE *fbuf, *rbuf, *readstat = NULL, *abuf;
580d49
 	struct message *mp;
580d49
 	int c;
580d49
-	char *tempResid;
580d49
+	char *tempResid = NULL;
580d49
 	struct stat minfo;
580d49
 
580d49
 	/*
580d49
@@ -313,6 +313,8 @@ cream:
580d49
 
580d49
 newmail:
580d49
 	printf(catgets(catd, CATSET, 166, "Thou hast new mail.\n"));
580d49
+	if (tempResid != NULL)
580d49
+		Ftfree(&tempResid);
580d49
 	if (fbuf != NULL) {
580d49
 		Fclose(fbuf);
580d49
 		dot_unlock(mailname);
580d49
diff --git a/send.c b/send.c
580d49
index ea3d5b7..40e6bda 100644
580d49
--- a/send.c
580d49
+++ b/send.c
580d49
@@ -568,6 +568,7 @@ skip:	switch (ip->m_mimecontent) {
580d49
 						Pclose(obuf);
580d49
 						safe_signal(SIGPIPE, oldpipe);
580d49
 					}
580d49
+					obuf = origobuf;
580d49
 				}
580d49
 			}
580d49
 			return rt;
580d49
diff --git a/sendout.c b/sendout.c
580d49
index f83952a..e734ee2 100644
580d49
--- a/sendout.c
580d49
+++ b/sendout.c
580d49
@@ -463,6 +463,7 @@ infix(struct header *hp, FILE *fi, int dosign)
580d49
 	if ((nfi = Fopen(tempMail, "r")) == NULL) {
580d49
 		perror(tempMail);
580d49
 		Fclose(nfo);
580d49
+		Ftfree(&tempMail);
580d49
 		return(NULL);
580d49
 	}
580d49
 	rm(tempMail);
580d49
@@ -1511,6 +1512,7 @@ resend_msg(struct message *mp, struct name *to, int add_resent)
580d49
 	if ((nfi = Fopen(tempMail, "r")) == NULL) {
580d49
 		senderr++;
580d49
 		perror(tempMail);
580d49
+		Ftfree(&tempMail);
580d49
 		return STOP;
580d49
 	}
580d49
 	rm(tempMail);
580d49
diff --git a/smtp.c b/smtp.c
580d49
index baab5d1..ce6870e 100644
580d49
--- a/smtp.c
580d49
+++ b/smtp.c
580d49
@@ -334,6 +334,7 @@ talk_smtp(struct name *to, FILE *fi, struct sock *sp,
580d49
 							  password);
580d49
 			b64 = memtob64(o, strlen(user)+strlen(password)+2);
580d49
 			snprintf(o, sizeof o, "%s\r\n", b64);
580d49
+			free(b64);
580d49
 			SMTP_OUT(o);
580d49
 			SMTP_ANSWER(2);
580d49
 			break;
580d49
diff --git a/ssl.c b/ssl.c
580d49
index 6a0b322..7fbe4a3 100644
580d49
--- a/ssl.c
580d49
+++ b/ssl.c
580d49
@@ -135,6 +135,8 @@ smime_split(FILE *ip, FILE **hp, FILE **bp, long xcount, int keep)
580d49
 	if ((*hp = Ftemp(&hn, "Rh", "w+", 0600, 1)) == NULL ||
580d49
 			(*bp = Ftemp(&bn, "Rb", "w+", 0600, 1)) == NULL) {
580d49
 		perror("tempfile");
580d49
+		if (hn)
580d49
+			Ftfree(&hn;;
580d49
 		return STOP;
580d49
 	}
580d49
 	rm(hn);
580d49
@@ -178,6 +180,7 @@ smime_split(FILE *ip, FILE **hp, FILE **bp, long xcount, int keep)
580d49
 		fwrite(buf, sizeof *buf, buflen, *bp);
580d49
 	fflush(*bp);
580d49
 	rewind(*bp);
580d49
+	free(savedfields);
580d49
 	free(buf);
580d49
 	return OKAY;
580d49
 }