Allocate new unsigned char buffer for processed line in heap, fixing crash

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-07-21 14:01:57 +08:00
Родитель 4d359bdb2a
Коммит 49a9f7f263
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -343,9 +343,10 @@
if (firstSeparatorIndex.location == NSNotFound) {
NSLog(@"No separator found. Creating new buffer qith space for null terminator.");
unsigned char newBuffer[inBufferLength + 1];
memcpy(&newBuffer, buffer, inBufferLength);
buffer = &newBuffer[0];
unsigned char *newBuffer = malloc(sizeof(unsigned char) * (inBufferLength + 1));
memcpy(newBuffer, buffer, inBufferLength);
buffer = newBuffer;
nullTerminatorIndex = inBufferLength;
} else {
nullTerminatorIndex = firstSeparatorIndex.location;