local_host_ip_addrs_to_string: fix buffer overflow

master
YuQing 2026-09-03 15:21:36 +08:00
parent 564facf33e
commit 15424dfc1c
3 changed files with 16 additions and 4 deletions

View File

@ -1,4 +1,7 @@
Version 1.88 2026-09-03
* local_host_ip_addrs_to_string: fix buffer overflow
Version 1.87 2026-07-10 Version 1.87 2026-07-10
* ini_file_readers can refer env variable such as %{env::FASTDFS_IPADDR} * ini_file_readers can refer env variable such as %{env::FASTDFS_IPADDR}

View File

@ -70,11 +70,20 @@ const char *local_host_ip_addrs_to_string(char *buff, const int size)
len = snprintf(buff, size, "local_host_ip_count: %d,", len = snprintf(buff, size, "local_host_ip_count: %d,",
g_local_host_ip_count); g_local_host_ip_count);
if (len >= size)
{
return buff;
}
pEnd = g_local_host_ip_addrs + pEnd = g_local_host_ip_addrs +
IP_ADDRESS_SIZE * g_local_host_ip_count; IP_ADDRESS_SIZE * g_local_host_ip_count;
for (p=g_local_host_ip_addrs; p<pEnd; p+=IP_ADDRESS_SIZE) for (p=g_local_host_ip_addrs; p<pEnd; p+=IP_ADDRESS_SIZE)
{ {
len += snprintf(buff + len, size - len, " %s", p); len += snprintf(buff + len, size - len, " %s", p);
if (len >= size)
{
break;
}
} }
return buff; return buff;