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:
Victor M. Alvarez
2024-02-08 11:28:17 +01:00
parent e4372d3a54
commit 3342aa06f6
+8 -4
View File
@@ -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);
}
}