8000 DynamicBufferString: Enforce null termination · troyhacks/ESPAsyncWebServer@71a4104 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71a4104

Browse files
committed
DynamicBufferString: Enforce null termination
1 parent 0af1ddf commit 71a4104

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/DynamicBuffer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ namespace {
88
// Inherit constructors
99
using String::String;
1010
DynamicBufferString(String&& s) : String(std::move(s)) {};
11-
DynamicBufferString(DynamicBuffer&& d) : String() {
11+
DynamicBufferString(DynamicBuffer&& d) : String() {
12+
auto capacity = d.size() - 1;
13+
auto buf = d.release();
14+
auto len = strnlen(buf, capacity);
15+
if (len == capacity) buf[len] = 0; // enforce null termination
1216
setSSO(false);
13-
setCapacity(d.size() - 1);
14-
setBuffer(d.release());
15-
setLen(strlen(ptr.buff));
17+
setBuffer(buf);
18+
setCapacity(capacity);
19+
setLen(len);
1620
}
1721

1822
// Special feature: releease the buffer to the caller without deallocating

0 commit comments

Comments
 (0)
0