Skip to content

Commit

Permalink
communication: Ensure string termination after strncpy
Browse files Browse the repository at this point in the history
  • Loading branch information
joveian authored Mar 30, 2023
1 parent 37f1a94 commit 358d0b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions communications.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ listen_for_commands(void)
rp_glob_screen.control_socket_path);

strncpy(sun.sun_path, rp_glob_screen.control_socket_path,
sizeof(sun.sun_path));
sizeof(sun.sun_path)-1);
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
sun.sun_family = AF_UNIX;

if (unlink(rp_glob_screen.control_socket_path) == -1 &&
Expand Down Expand Up @@ -113,7 +114,8 @@ send_command(int interactive, unsigned char *cmd)
rp_glob_screen.control_socket_path);

strncpy(sun.sun_path, rp_glob_screen.control_socket_path,
sizeof(sun.sun_path));
sizeof(sun.sun_path)-1);
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
sun.sun_family = AF_UNIX;

if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
Expand Down

0 comments on commit 358d0b4

Please sign in to comment.