From 2cfedab3396722c10e8731f1b92527593f1a7257 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Wed, 20 Sep 2017 21:21:44 -0700 Subject: [PATCH] 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. --- tasks/task_database_cue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index a0e7948789..589f1d4312 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -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;