From 1e5bbbdf1b5461f889d4ee28544af09c2ff9d2aa Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Tue, 20 Feb 2018 05:31:09 +0000
Subject: [PATCH] Address Coverity-scan reported issues.

---
 src/sbbs3/sexyz.c  | 5 +++--
 src/sbbs3/xmodem.c | 8 ++++++--
 src/sbbs3/zmodem.c | 4 ++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/sbbs3/sexyz.c b/src/sbbs3/sexyz.c
index 33bbc4f003..abe60bf1dd 100644
--- a/src/sbbs3/sexyz.c
+++ b/src/sbbs3/sexyz.c
@@ -1332,6 +1332,7 @@ static int receive_files(char** fname_list, int fnames)
 				if(fwrite(block,1,wr,fp)!=wr) {
 					lprintf(LOG_ERR,"ERROR %d writing %u bytes at file offset %"PRIu64
 						,errno, wr, (uint64_t)ftello(fp));
+					fclose(fp);
 					xmodem_cancel(&xm);
 					return(1); 
 				}
@@ -1884,7 +1885,7 @@ int main(int argc, char **argv)
 	if(!stdio) {
 #endif
 		lprintf(LOG_DEBUG,"Setting TCP_NODELAY to %d",tcp_nodelay);
-		setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&tcp_nodelay,sizeof(tcp_nodelay));
+		(void)setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&tcp_nodelay,sizeof(tcp_nodelay));
 #ifdef __unix__
 	}
 #endif
@@ -1892,7 +1893,7 @@ int main(int argc, char **argv)
 	/* Set non-blocking mode */
 #ifdef __unix__
 	if(stdio) {
-		fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK);
+		(void)fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL) | O_NONBLOCK);
 	}
 	else
 #endif
diff --git a/src/sbbs3/xmodem.c b/src/sbbs3/xmodem.c
index 3d4ab3ef70..2ff45d59e8 100644
--- a/src/sbbs3/xmodem.c
+++ b/src/sbbs3/xmodem.c
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
  *																			*
  * This program is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU General Public License				*
@@ -233,6 +233,7 @@ int xmodem_get_block(xmodem_t* xm, uchar* block, unsigned expected_block_num)
 			default:
 				lprintf(xm,LOG_WARNING,"Block %u: Received %s  Expected SOH, STX, or EOT"
 					,expected_block_num, chr((uchar)i));
+				/* Fall-through */
 			case NOINP: 	/* Nothing came in */
 				if(eot)
 					return(EOT);
@@ -492,7 +493,10 @@ BOOL xmodem_send_file(xmodem_t* xm, const char* fname, FILE* fp, time_t* start,
 	if(start!=NULL)		
 		*start=time(NULL);
 
-	fstat(fileno(fp),&st);
+	if(fstat(fileno(fp),&st) != 0) {
+		lprintf(xm,LOG_ERR,"Failed to fstat file");
+		return FALSE;
+	}
 
 	if(xm->total_files==0)
 		xm->total_files=1;
diff --git a/src/sbbs3/zmodem.c b/src/sbbs3/zmodem.c
index 4c6c30cc2f..e2626e4408 100644
--- a/src/sbbs3/zmodem.c
+++ b/src/sbbs3/zmodem.c
@@ -2013,6 +2013,10 @@ int zmodem_recv_files(zmodem_t* zm, const char* download_dir, uint64_t* bytes_re
 				break;
 			}
 			start_bytes=filelength(fileno(fp));
+			if(start_bytes < 0) {
+				lprintf(zm,LOG_ERR,"Invalid file length %"PRId64": %s", start_bytes, fpath);
+				break;
+			}
 
 			skip=FALSE;
 			errors=zmodem_recv_file_data(zm,fp,start_bytes);
-- 
GitLab