--- lbbs/src/net_server.c 2025/05/04 14:54:55 1.15 +++ lbbs/src/net_server.c 2025/05/06 05:31:26 1.18 @@ -1,16 +1,15 @@ /*************************************************************************** net_server.c - description ------------------- - begin : Mon Oct 11 2004 - copyright : (C) 2004 by Leaflet - email : leaflet@leafok.com + Copyright : (C) 2004-2025 by Leaflet + Email : leaflet@leafok.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * + * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ @@ -22,10 +21,9 @@ #include "fork.h" #include "tcplib.h" #include -#include #include -int net_server(const char *hostaddr, unsigned int port) +int net_server(const char *hostaddr, in_port_t port) { unsigned int namelen; int result; @@ -44,7 +42,7 @@ int net_server(const char *hostaddr, uns sin.sin_family = AF_INET; sin.sin_addr.s_addr = - (strlen(hostaddr) > 0 ? inet_addr(hostaddr) : INADDR_ANY); + (strnlen(hostaddr, sizeof(hostaddr)) > 0 ? inet_addr(hostaddr) : INADDR_ANY); sin.sin_port = htons(port); if (bind(socket_server, (struct sockaddr *)&sin, sizeof(sin)) < 0) @@ -60,7 +58,9 @@ int net_server(const char *hostaddr, uns exit(3); } - strcpy(hostaddr_server, inet_ntoa(sin.sin_addr)); + strncpy(hostaddr_server, inet_ntoa(sin.sin_addr), sizeof(hostaddr_server) - 1); + hostaddr_server[sizeof(hostaddr_server) - 1] = '\0'; + port_server = ntohs(sin.sin_port); log_std("Listening at %s:%d\n", hostaddr_server, port_server); @@ -108,7 +108,9 @@ int net_server(const char *hostaddr, uns continue; } - strcpy(hostaddr_client, (const char *)inet_ntoa(sin.sin_addr)); + strncpy(hostaddr_client, inet_ntoa(sin.sin_addr), sizeof(hostaddr_client) - 1); + hostaddr_client[sizeof(hostaddr_client) - 1] = '\0'; + port_client = ntohs(sin.sin_port); log_std("Accept connection from %s:%d\n", hostaddr_client,