Ensure 0 termination of the buffer being converted to a string.
The file content isn't normally 0 terminated, so making a string out of it would usually result in reading beyond the allocated buffer to find the string length, possibly leading to a crash.
This commit is contained in:
parent
232ba1d6f6
commit
6ba5fa4d64
@ -1836,15 +1836,17 @@ TRoster::_LoadRosterSettings(const char* path)
|
||||
char* data = NULL;
|
||||
|
||||
if (!error) {
|
||||
data = new(nothrow) char[size];
|
||||
data = new(nothrow) char[size + 1];
|
||||
error = data ? B_OK : B_NO_MEMORY;
|
||||
}
|
||||
if (!error) {
|
||||
ssize_t bytes = file.Read(data, size);
|
||||
error = bytes < 0 ? bytes : (bytes == size ? B_OK : B_FILE_ERROR);
|
||||
}
|
||||
if (!error)
|
||||
if (!error) {
|
||||
data[size] = 0;
|
||||
error = stream.SetTo(std::string(data));
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user