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