mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
Fix potential use-after-free and overlapping memory copy in ffStrbufSetNS
This commit is contained in:
committed by
Carter Li
parent
5fe2cc6350
commit
2b82e9ab02
@@ -248,14 +248,17 @@ void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value) {
|
||||
assert(value != NULL);
|
||||
|
||||
if (strbuf->allocated < length + 1) {
|
||||
char* newBuf = malloc(sizeof(char) * (length + 1));
|
||||
memcpy(newBuf, value, length);
|
||||
if (strbuf->allocated > 0) {
|
||||
free(strbuf->chars);
|
||||
}
|
||||
strbuf->chars = newBuf;
|
||||
strbuf->allocated = length + 1;
|
||||
strbuf->chars = malloc(sizeof(char) * strbuf->allocated);
|
||||
} else {
|
||||
memmove(strbuf->chars, value, length);
|
||||
}
|
||||
|
||||
memcpy(strbuf->chars, value, length);
|
||||
strbuf->length = length;
|
||||
strbuf->chars[length] = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user