From fdd098b010894dfbaf8c55648d7ecdaa7d8ceb52 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 23 Jul 2011 22:22:36 +0200 Subject: [PATCH] secure strscpy by replacing with strncpy --- i3-input/ipc.c | 2 +- i3-msg/main.c | 2 +- src/ipc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/i3-input/ipc.c b/i3-input/ipc.c index 597a86ef..2d11f0e0 100644 --- a/i3-input/ipc.c +++ b/i3-input/ipc.c @@ -60,7 +60,7 @@ int connect_ipc(char *socket_path) { struct sockaddr_un addr; memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_LOCAL; - strcpy(addr.sun_path, socket_path); + strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) err(EXIT_FAILURE, "Could not connect to i3"); diff --git a/i3-msg/main.c b/i3-msg/main.c index ac08419f..630a345d 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -231,7 +231,7 @@ int main(int argc, char *argv[]) { struct sockaddr_un addr; memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_LOCAL; - strcpy(addr.sun_path, socket_path); + strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1); if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) err(EXIT_FAILURE, "Could not connect to i3"); diff --git a/src/ipc.c b/src/ipc.c index 1dd9512a..acd09e8f 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -77,7 +77,7 @@ static void ipc_send_message(int fd, const unsigned char *payload, char msg[buffer_size]; char *walk = msg; - strcpy(walk, "i3-ipc"); + strncpy(walk, "i3-ipc", buffer_size - 1); walk += strlen("i3-ipc"); memcpy(walk, &message_size, sizeof(uint32_t)); walk += sizeof(uint32_t); -- 2.39.5