Skip to content

Commit

Permalink
ensure null termination following strncpy(), gcc 8 -Wstringop-truncat…
Browse files Browse the repository at this point in the history
…ion err
  • Loading branch information
mjfitzpatrick committed Oct 17, 2023
1 parent 1dfb2a7 commit ab2ec08
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions unix/os/zfiond.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ ZOPNND (
sockaddr.sun_family = AF_UNIX;
strncpy (sockaddr.sun_path,
np->path1, sizeof(sockaddr.sun_path));
#ifdef MACOSX
sockaddr.sun_path[103] = '\0'; // ensure NULL termination
#else
sockaddr.sun_path[107] = '\0'; // ensure NULL termination
#endif

/* Connect to server. */
if (fd >= MAXOFILES || (connect (fd,
Expand Down Expand Up @@ -478,6 +483,11 @@ ZOPNND (
bzero ((char *)&sockaddr, sizeof(sockaddr));
sockaddr.sun_family = AF_UNIX;
strncpy (sockaddr.sun_path,np->path1,sizeof(sockaddr.sun_path));
#ifdef MACOSX
sockaddr.sun_path[103] = '\0'; // ensure NULL termination
#else
sockaddr.sun_path[107] = '\0'; // ensure NULL termination
#endif
addrlen = sizeof(sockaddr) - sizeof(sockaddr.sun_path)
+ strlen(np->path1);

Expand Down

0 comments on commit ab2ec08

Please sign in to comment.