File fcoe-utils-use-strncpy-in-fcoemon of Package open-fcoe

From 9469f11e17ebadab475b8d4de23bb3cf9b1bc8db Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 22 Jan 2010 09:03:35 +0100
Subject: [PATCH] Use strncpy not memcpy when copying sun_path

Occasionally fcoemon fails to reply to a fcoeadm request.
When this happens fcoeadm eventually times out. It is the
result of using memcpy and not strncpy when copying the
sun_path received from the request.

Using memcpy is causing intermittent problems when copying
the sun_path from socket information. sun_path is a string
and therefore strncpy should be used. memcpy is not going to
copy the terminating character becuase we're using strlen
to determine the number of bytes to be copied.

The problem is masked becuase much of the time the destination
buffer must have been allocated from NULL'd out memory, but if
the allocated buffer started with junk characters then the code
ends up copying into a buffer without termination. So when we
try to reply to fcoeadm the sendto interface complains that
the sun_path is invalid (becuase there is garbage in the string).

This patch makes it so strncpy is used since we're dealing
with strings. It also changes the last argument to be the
size of the destination buffer as that's what strncpy requires.

References: bnc#572893

Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>

diff --git a/fcoemon.c b/fcoemon.c
index 2847da4..a8e25d7 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -2165,7 +2165,7 @@ int fcm_save_reply(struct sock_info **r, struct sockaddr_un *f, socklen_t flen,
 		}
 		(*r)->sock = s;
 		(*r)->from.sun_family = f->sun_family;
-		memcpy((*r)->from.sun_path, f->sun_path, strlen(f->sun_path));
+		strncpy((*r)->from.sun_path, f->sun_path, sizeof((*r)->from.sun_path));
 		(*r)->fromlen = flen;
 		return fcm_success;
 	}
openSUSE Build Service is sponsored by