Fix use after free.

As pointed by Marcus, FindString returns a pointer to the internal data
of the BMessage, so the message must stay in scope as long as we use the
pointer.

Thanks for reviewing!
This commit is contained in:
Adrien Destugues 2017-04-02 08:23:01 +02:00
parent ad7a5be908
commit d5bff72ed8

View File

@ -249,10 +249,10 @@ StreamBase::Open()
// For this we need some valid data in the buffer, the first 512 bytes
// should do because our MIME sniffing never uses more.
const char* extension = NULL;
BMessage message;
if (fSource->Read(buffer, 512) == 512) {
BMimeType type;
if (BMimeType::GuessMimeType(buffer, 512, &type) == B_OK) {
BMessage message;
if (type.GetFileExtensions(&message) == B_OK) {
extension = message.FindString("extensions");
}