Prevent passing NULL/empty strings to memcmp

This commit is contained in:
twinaphex 2017-05-28 18:07:00 +02:00
parent d8f1cf7b5a
commit cf2f8f6489
1 changed files with 83 additions and 72 deletions

View File

@ -277,6 +277,9 @@ int detect_psp_game(const char *track_path, char *game_id)
if (filestream_read(fd, game_id, 5) > 0)
{
game_id[5] = '\0';
if (!string_is_empty(game_id))
{
if (
(string_is_equal_fast(game_id, "ULES-", 5))
|| (string_is_equal_fast(game_id, "ULUS-", 5))
@ -319,6 +322,7 @@ int detect_psp_game(const char *track_path, char *game_id)
break;
}
}
}
else
break;
}
@ -346,6 +350,7 @@ int detect_system(const char *track_path, const char **system_name)
for (i = 0; MAGIC_NUMBERS[i].system_name != NULL; i++)
{
filestream_seek(fd, MAGIC_NUMBERS[i].offset, SEEK_SET);
if (filestream_read(fd, magic, MAGIC_LEN) < MAGIC_LEN)
{
RARCH_LOG("Could not read data from file '%s' at offset %d: %s\n",
@ -354,7 +359,9 @@ int detect_system(const char *track_path, const char **system_name)
goto clean;
}
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
if (!string_is_empty(MAGIC_NUMBERS[i].magic) &&
!string_is_empty(magic) &&
string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
{
*system_name = MAGIC_NUMBERS[i].system_name;
rv = 0;
@ -366,7 +373,8 @@ int detect_system(const char *track_path, const char **system_name)
if (filestream_read(fd, magic, 8) > 0)
{
magic[8] = '\0';
if (string_is_equal_fast(magic, "PSP GAME", 8))
if (!string_is_empty(magic) &&
string_is_equal_fast(magic, "PSP GAME", 8))
{
*system_name = "psp\0";
rv = 0;
@ -402,6 +410,8 @@ int find_first_data_track(const char *cue_path,
tmp_token[0] = '\0';
while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
{
if (!string_is_empty(tmp_token))
{
if (string_is_equal_fast(tmp_token, "FILE", 4))
{
@ -445,6 +455,7 @@ int find_first_data_track(const char *cue_path,
goto clean;
}
}
}
rv = -EINVAL;