mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
task_database_cue: only return error when errno would be set
On a short read, errno will be 0, and returning 0 without setting system_name will cause a crash later. Just continue to the next magic number instead.
This commit is contained in:
parent
f58329d921
commit
2cfedab339
@ -337,13 +337,15 @@ int detect_system(intfstream_t *fd, const char **system_name)
|
|||||||
int rv;
|
int rv;
|
||||||
char magic[MAGIC_LEN];
|
char magic[MAGIC_LEN];
|
||||||
int i;
|
int i;
|
||||||
|
ssize_t read;
|
||||||
|
|
||||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
|
||||||
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
|
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
|
||||||
{
|
{
|
||||||
intfstream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);
|
intfstream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);
|
||||||
|
|
||||||
if (intfstream_read(fd, magic, MAGIC_LEN) < MAGIC_LEN)
|
read = intfstream_read(fd, magic, MAGIC_LEN);
|
||||||
|
if (read < 0)
|
||||||
{
|
{
|
||||||
RARCH_LOG("Could not read data at offset %d: %s\n",
|
RARCH_LOG("Could not read data at offset %d: %s\n",
|
||||||
MAGIC_NUMBERS[i].offset, strerror(errno));
|
MAGIC_NUMBERS[i].offset, strerror(errno));
|
||||||
@ -351,6 +353,9 @@ int detect_system(intfstream_t *fd, const char **system_name)
|
|||||||
goto clean;
|
goto clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (read < MAGIC_LEN)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
|
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
|
||||||
{
|
{
|
||||||
*system_name = MAGIC_NUMBERS[i].system_name;
|
*system_name = MAGIC_NUMBERS[i].system_name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user