Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
secure strscpy by replacing with strncpy
Browse files Browse the repository at this point in the history
  • Loading branch information
stapelberg committed Jul 23, 2011
1 parent a402480 commit fdd098b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion i3-input/ipc.c
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion i3-msg/main.c
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/ipc.c
Expand Up @@ -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);
Expand Down

0 comments on commit fdd098b

Please sign in to comment.