1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Fix another charpool blunder: null goes at end of string, not end of allocation.

This commit is contained in:
dmiller
2022-09-16 22:40:25 +00:00
parent fb64aa9738
commit fb29dba40e

View File

@@ -106,14 +106,16 @@ void CharPool::clear(void) {
}
const char *CharPool::dup(const char *src, int len) {
int sz = len < 0 ? strlen(src) : len;
if (len < 0)
len = strlen(src);
int sz = len + 1;
char *p = buckets.back() + nexti;
int modulus;
if ((modulus = sz % ALIGN_ON))
sz += ALIGN_ON - modulus;
while (nexti + sz > currentbucketsz - 1) {
while (nexti + sz > currentbucketsz) {
/* Doh! We've got to make room */
currentbucketsz <<= 1;
nexti = 0;
@@ -121,7 +123,7 @@ const char *CharPool::dup(const char *src, int len) {
buckets.push_back(p);
}
nexti += sz + 1;
p[sz] = '\0';
return (const char *) memcpy(p, src, sz);
nexti += sz;
p[len] = '\0';
return (const char *) memcpy(p, src, len);
}