Procházet zdrojové kódy

qdevice unix-socket: Fix snprintf warning

Base N on sizeof sun_path instead of strlen of input path.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>

(cherry picked from corosync-qdevice project commit
 466ab62f106c0f469c1c6e36ddf825cf7c67d899)
Jan Friesse před 7 roky
rodič
revize
42ed6f9f1b
1 změnil soubory, kde provedl 2 přidání a 2 odebrání
  1. 2 2
      qdevices/unix-socket.c

+ 2 - 2
qdevices/unix-socket.c

@@ -60,7 +60,7 @@ unix_socket_server_create(const char *path, int non_blocking, int backlog)
 	memset(&sun, 0, sizeof(sun));
 	memset(&sun, 0, sizeof(sun));
 	sun.sun_family = AF_UNIX;
 	sun.sun_family = AF_UNIX;
 
 
-	strncpy(sun.sun_path, path, strlen(path));
+	strncpy(sun.sun_path, path, sizeof(sun.sun_path) - 1);
 	unlink(path);
 	unlink(path);
 	if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) != 0) {
 	if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) != 0) {
 		close(s);
 		close(s);
@@ -103,7 +103,7 @@ unix_socket_client_create(const char *path, int non_blocking)
 	memset(&sun, 0, sizeof(sun));
 	memset(&sun, 0, sizeof(sun));
 	sun.sun_family = AF_UNIX;
 	sun.sun_family = AF_UNIX;
 
 
-	strncpy(sun.sun_path, path, strlen(path));
+	strncpy(sun.sun_path, path, sizeof(sun.sun_path) - 1);
 
 
 	if (non_blocking) {
 	if (non_blocking) {
 		if (utils_fd_set_non_blocking(s) != 0) {
 		if (utils_fd_set_non_blocking(s) != 0) {