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
* ini_file_readers can refer env variable such as %{env::FASTDFS_IPADDR}

View File

@ -10,7 +10,7 @@ libfastcommon是在github开源的⼀个C函数库。它提供了ini⽂件解析
## ini_file_reader的主要特点
### 1、⽀持section
例如:
例如:
```
[workers]
threads = 4

View File

@ -70,12 +70,21 @@ const char *local_host_ip_addrs_to_string(char *buff, const int size)
len = snprintf(buff, size, "local_host_ip_count: %d,",
g_local_host_ip_count);
if (len >= size)
{
return buff;
}
pEnd = g_local_host_ip_addrs +
IP_ADDRESS_SIZE * g_local_host_ip_count;
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;
}