mirror of
https://github.com/VirusTotal/yara.git
synced 2026-10-11 22:49:58 +00:00
Fix bug in magic module when libmagic returns null pointer.
The pointer returned from `libmagic` was passed directly to `yr_strdup` (a wrapper of `strdup`), but this function has undefined behavior when the argument is null.
This commit is contained in:
@@ -111,8 +111,10 @@ define_function(magic_mime_type)
|
||||
{
|
||||
magic_setflags(cache->magic_cookie, MAGIC_MIME_TYPE);
|
||||
|
||||
cache->cached_mime_type = yr_strdup(
|
||||
magic_buffer(cache->magic_cookie, block_data, block->size));
|
||||
const char* type = magic_buffer(
|
||||
cache->magic_cookie, block_data, block->size);
|
||||
|
||||
cache->cached_mime_type = (type == NULL) ? NULL : yr_strdup(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,8 +150,10 @@ define_function(magic_type)
|
||||
{
|
||||
magic_setflags(cache->magic_cookie, 0);
|
||||
|
||||
cache->cached_type = yr_strdup(
|
||||
magic_buffer(cache->magic_cookie, block_data, block->size));
|
||||
const char* type = magic_buffer(
|
||||
cache->magic_cookie, block_data, block->size);
|
||||
|
||||
cache->cached_type = (type == NULL) ? NULL : yr_strdup(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user