]> prime8.dev >> repos - ttyd.git/commitdiff
bugfix: off by one error (#257)
authorDennis Chen <barracks510@gmail.com>
Thu, 2 Jan 2020 13:30:58 +0000 (07:30 -0600)
committerShuanglei Tao <tsl0922@gmail.com>
Thu, 2 Jan 2020 13:30:58 +0000 (21:30 +0800)
The strncpy function requires enough space for a NUL terminator.

src/server.c

index 74530442772ef2bbb8be462fd71ff723bfa6a20c..d586c8a60232dab895bd10eb030478abb75472c0 100644 (file)
@@ -431,7 +431,7 @@ main(int argc, char **argv) {
         if (endswith(info.iface, ".sock") || endswith(info.iface, ".socket")) {
 #if defined(LWS_USE_UNIX_SOCK) || defined(LWS_WITH_UNIX_SOCK)
             info.options |= LWS_SERVER_OPTION_UNIX_SOCK;
-            strncpy(server->socket_path, info.iface, sizeof(server->socket_path));
+            strncpy(server->socket_path, info.iface, sizeof(server->socket_path) - 1);
 #else
             fprintf(stderr, "libwebsockets is not compiled with UNIX domain socket support");
             return -1;