--- lbbs/src/net_server.c 2025/04/28 03:31:00 1.13 +++ lbbs/src/net_server.c 2025/05/06 05:31:26 1.18 @@ -1,32 +1,34 @@ /*************************************************************************** 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. * * * ***************************************************************************/ +#include "net_server.h" #include "common.h" +#include "log.h" #include "io.h" +#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) { - int namelen, seq, netint, result, flags; + unsigned int namelen; + int result; + int flags; struct sockaddr_in sin; - char temp[256]; fd_set testfds; struct timeval timeout; @@ -40,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) @@ -56,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); @@ -104,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,