[PATCH 1/7] cleanups: Fix resource leak and buffer overrun in daemon.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Address two reports from an automatic code analyzer:

1. In logreport, it is possible to write \0 one
character past the end of buf[].

2. In socksetup, socklist can be leaked when returning
if set_reuse_addr().  Note: dunno why this case returns...

Signed-off-by: Serge E. Hallyn <serue@xxxxxxxxxx>

---

 daemon.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

5b3e0254d34da582b7593084356c88a923f42a49
diff --git a/daemon.c b/daemon.c
index a1ccda3..7ac1bc7 100644
--- a/daemon.c
+++ b/daemon.c
@@ -65,8 +65,8 @@ static void logreport(int priority, cons
 	 * we have space for our own LF and NUL after the "meat" of the
 	 * message, so truncate it at maxlen - 1.
 	 */
-	if (msglen > maxlen - 1)
-		msglen = maxlen - 1;
+	if (msglen > maxlen - 2)
+		msglen = maxlen - 2;
 	else if (msglen < 0)
 		msglen = 0; /* Protect against weird return values. */
 	buflen += msglen;
@@ -535,6 +535,7 @@ static int socksetup(int port, int **soc
 
 		if (set_reuse_addr(sockfd)) {
 			close(sockfd);
+			free(socklist);
 			return 0;	/* not fatal */
 		}
 
-- 
1.2.5


-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]