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:
Brian Koropoff 2017-09-20 21:21:44 -07:00
parent f58329d921
commit 2cfedab339

View File

@ -337,13 +337,15 @@ int detect_system(intfstream_t *fd, const char **system_name)
int rv;
char magic[MAGIC_LEN];
int i;
ssize_t read;
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS));
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
{
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",
MAGIC_NUMBERS[i].offset, strerror(errno));
@ -351,6 +353,9 @@ int detect_system(intfstream_t *fd, const char **system_name)
goto clean;
}
if (read < MAGIC_LEN)
continue;
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
{
*system_name = MAGIC_NUMBERS[i].system_name;