secure strcpy by replacing with strncpy

This commit is contained in:
Christopher Zimmermann 2010-07-15 14:38:29 +02:00 committed by Michael Stapelberg
parent 95eb1f22c5
commit 63a9647a2c
3 changed files with 3 additions and 3 deletions

View File

@ -60,7 +60,7 @@ int connect_ipc(char *socket_path) {
struct sockaddr_un addr; struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un)); memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL; 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) if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
err(EXIT_FAILURE, "Could not connect to i3"); err(EXIT_FAILURE, "Could not connect to i3");

View File

@ -175,7 +175,7 @@ int main(int argc, char *argv[]) {
struct sockaddr_un addr; struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un)); memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL; 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) if (connect(sockfd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0)
err(EXIT_FAILURE, "Could not connect to i3"); err(EXIT_FAILURE, "Could not connect to i3");

View File

@ -91,7 +91,7 @@ static void ipc_send_message(int fd, const unsigned char *payload,
char msg[buffer_size]; char msg[buffer_size];
char *walk = msg; char *walk = msg;
strcpy(walk, "i3-ipc"); strncpy(walk, "i3-ipc", buffer_size - 1);
walk += strlen("i3-ipc"); walk += strlen("i3-ipc");
memcpy(walk, &message_size, sizeof(uint32_t)); memcpy(walk, &message_size, sizeof(uint32_t));
walk += sizeof(uint32_t); walk += sizeof(uint32_t);