mirror of
https://github.com/libretro/RetroArch
synced 2025-02-01 00:32:46 +00:00
Merge pull request #8479 from jdgleaver/strlcpy-checks
strlcpy() safety checks
This commit is contained in:
commit
5919171181
@ -243,6 +243,8 @@ bool menu_thumbnail_set_content(menu_thumbnail_path_data_t *path_data, const cha
|
|||||||
* Returns true if content is valid */
|
* Returns true if content is valid */
|
||||||
bool menu_thumbnail_set_content_image(menu_thumbnail_path_data_t *path_data, const char *img_dir, const char *img_name)
|
bool menu_thumbnail_set_content_image(menu_thumbnail_path_data_t *path_data, const char *img_dir, const char *img_name)
|
||||||
{
|
{
|
||||||
|
char *content_img_no_ext = NULL;
|
||||||
|
|
||||||
if (!path_data)
|
if (!path_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -272,8 +274,13 @@ bool menu_thumbnail_set_content_image(menu_thumbnail_path_data_t *path_data, con
|
|||||||
img_name, sizeof(path_data->content_img));
|
img_name, sizeof(path_data->content_img));
|
||||||
|
|
||||||
/* Get image label */
|
/* Get image label */
|
||||||
strlcpy(path_data->content_label,
|
content_img_no_ext = path_remove_extension(path_data->content_img);
|
||||||
path_remove_extension(path_data->content_img), sizeof(path_data->content_label));
|
if (!string_is_empty(content_img_no_ext))
|
||||||
|
strlcpy(path_data->content_label,
|
||||||
|
content_img_no_ext, sizeof(path_data->content_label));
|
||||||
|
else
|
||||||
|
strlcpy(path_data->content_label,
|
||||||
|
path_data->content_img, sizeof(path_data->content_label));
|
||||||
|
|
||||||
/* Set file path */
|
/* Set file path */
|
||||||
fill_pathname_join(path_data->content_path,
|
fill_pathname_join(path_data->content_path,
|
||||||
@ -376,16 +383,22 @@ bool menu_thumbnail_set_content_playlist(menu_thumbnail_path_data_t *path_data,
|
|||||||
"MAME", sizeof(path_data->content_db_name));
|
"MAME", sizeof(path_data->content_db_name));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
char *db_name_no_ext = NULL;
|
||||||
char tmp_buf[PATH_MAX_LENGTH];
|
char tmp_buf[PATH_MAX_LENGTH];
|
||||||
tmp_buf[0] = '\0';
|
tmp_buf[0] = '\0';
|
||||||
|
|
||||||
strlcpy(tmp_buf, db_name, sizeof(tmp_buf));
|
|
||||||
|
|
||||||
/* Remove .lpl extension
|
/* Remove .lpl extension
|
||||||
* > path_remove_extension() requires a char * (not const)
|
* > path_remove_extension() requires a char * (not const)
|
||||||
* so have to use a temporary buffer... */
|
* so have to use a temporary buffer... */
|
||||||
strlcpy(path_data->content_db_name,
|
strlcpy(tmp_buf, db_name, sizeof(tmp_buf));
|
||||||
path_remove_extension(tmp_buf), sizeof(path_data->content_db_name));
|
db_name_no_ext = path_remove_extension(tmp_buf);
|
||||||
|
|
||||||
|
if (!string_is_empty(db_name_no_ext))
|
||||||
|
strlcpy(path_data->content_db_name,
|
||||||
|
db_name_no_ext, sizeof(path_data->content_db_name));
|
||||||
|
else
|
||||||
|
strlcpy(path_data->content_db_name,
|
||||||
|
tmp_buf, sizeof(path_data->content_db_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,8 +319,13 @@ runtime_log_t *runtime_log_init(const char *content_path, const char *core_path,
|
|||||||
{
|
{
|
||||||
if (string_is_equal(path_basename(core_info->list[i].path), core_path_basename))
|
if (string_is_equal(path_basename(core_info->list[i].path), core_path_basename))
|
||||||
{
|
{
|
||||||
strlcpy(core_name, core_info->list[i].core_name, sizeof(core_name));
|
if (!string_is_empty(core_info->list[i].core_name))
|
||||||
break;
|
{
|
||||||
|
strlcpy(core_name, core_info->list[i].core_name, sizeof(core_name));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +346,9 @@ runtime_log_t *runtime_log_init(const char *content_path, const char *core_path,
|
|||||||
else
|
else
|
||||||
strlcpy(tmp_buf, settings->paths.directory_runtime_log, sizeof(tmp_buf));
|
strlcpy(tmp_buf, settings->paths.directory_runtime_log, sizeof(tmp_buf));
|
||||||
|
|
||||||
|
if (string_is_empty(tmp_buf))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (log_per_core)
|
if (log_per_core)
|
||||||
{
|
{
|
||||||
fill_pathname_join(
|
fill_pathname_join(
|
||||||
@ -388,9 +396,14 @@ runtime_log_t *runtime_log_init(const char *content_path, const char *core_path,
|
|||||||
{
|
{
|
||||||
/* path_remove_extension() requires a char * (not const)
|
/* path_remove_extension() requires a char * (not const)
|
||||||
* so have to use a temporary buffer... */
|
* so have to use a temporary buffer... */
|
||||||
|
char *tmp_buf_no_ext = NULL;
|
||||||
tmp_buf[0] = '\0';
|
tmp_buf[0] = '\0';
|
||||||
strlcpy(tmp_buf, path_basename(content_path), sizeof(tmp_buf));
|
strlcpy(tmp_buf, path_basename(content_path), sizeof(tmp_buf));
|
||||||
strlcpy(content_name, path_remove_extension(tmp_buf), sizeof(content_name));
|
tmp_buf_no_ext = path_remove_extension(tmp_buf);
|
||||||
|
if (!string_is_empty(tmp_buf_no_ext))
|
||||||
|
strlcpy(content_name, tmp_buf_no_ext, sizeof(content_name));
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string_is_empty(content_name))
|
if (string_is_empty(content_name))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user