Don't do NULL termination on string if we pass it off to strlcpy

and/or a file_path function that uses strlcpy under the hood
This commit is contained in:
libretroadmin 2022-07-24 05:39:51 +02:00
parent cc7c310aa1
commit 69a2d124c0
12 changed files with 24 additions and 138 deletions

View File

@ -468,20 +468,15 @@ bool task_push_audio_mixer_load_and_play(
const char *ext = NULL;
char ext_lower[6];
ext_lower[0] = '\0';
if (!t || !user)
goto error;
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
if (!nbio)
if (!(nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio))))
goto error;
nbio->path = strdup(fullpath);
mixer = (struct audio_mixer_handle*)calloc(1, sizeof(*mixer));
if (!mixer)
if (!(mixer = (struct audio_mixer_handle*)calloc(1, sizeof(*mixer))))
goto error;
mixer->is_finished = false;
@ -492,7 +487,7 @@ bool task_push_audio_mixer_load_and_play(
mixer->type = AUDIO_MIXER_TYPE_NONE;
/* Get file extension */
ext = strrchr(fullpath, '.');
ext = strrchr(fullpath, '.');
if (!ext || (*(++ext) == '\0'))
goto error;
@ -599,20 +594,15 @@ bool task_push_audio_mixer_load(
const char *ext = NULL;
char ext_lower[6];
ext_lower[0] = '\0';
if (!t || !user)
goto error;
nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio));
if (!nbio)
if (!(nbio = (nbio_handle_t*)calloc(1, sizeof(*nbio))))
goto error;
nbio->path = strdup(fullpath);
mixer = (struct audio_mixer_handle*)calloc(1, sizeof(*mixer));
if (!mixer)
if (!(mixer = (struct audio_mixer_handle*)calloc(1, sizeof(*mixer))))
goto error;
mixer->is_finished = false;

View File

@ -424,7 +424,6 @@ static void input_autoconfigure_connect_handler(retro_task_t *task)
bool match_found = false;
const char *device_display_name = NULL;
char task_title[NAME_MAX_LENGTH + 16];
task_title[0] = '\0';
if (!task)
@ -643,8 +642,6 @@ bool input_autoconfigure_connect(
if (driver_valid)
{
char dir_driver_autoconfig[PATH_MAX_LENGTH];
dir_driver_autoconfig[0] = '\0';
/* Generate driver-specific autoconfig directory */
fill_pathname_join(dir_driver_autoconfig, dir_autoconfig,
autoconfig_handle->device_info.joypad_driver,

View File

@ -519,7 +519,6 @@ void input_autoconfigure_blissbox_override_handler(
/* override name given to autoconfig so it knows what kind of pad this is */
if (len > 0)
{
device_name[0] = '\0';
strlcpy(device_name, "Bliss-Box 4-Play ", len);
strlcat(device_name, pad->name, len);
}

View File

@ -545,9 +545,6 @@ static bool content_file_list_set_info(
const char *archive_delim = NULL;
const char *ext = NULL;
dir[0] = '\0';
name[0] = '\0';
/* 'Full' path - may point to a file
* inside an archive */
file_info->full_path = strdup(path);
@ -1038,8 +1035,6 @@ static bool content_file_load(
char new_basedir[PATH_MAX_LENGTH];
char new_path[PATH_MAX_LENGTH];
new_path[0] = '\0';
RARCH_LOG("[Content]: Core does not support VFS"
" - copying to cache directory.\n");

View File

@ -150,8 +150,6 @@ static void task_cdrom_dump_handler(retro_task_t *task)
int64_t cue_size = filestream_get_size(state->file);
char *cue_data = (char*)calloc(1, cue_size);
output_file[0] = cue_filename[0] = '\0';
filestream_read(state->file, cue_data, cue_size);
state->stream = filestream_get_vfs_handle(state->file);
@ -162,7 +160,8 @@ static void task_cdrom_dump_handler(retro_task_t *task)
filestream_close(state->file);
snprintf(cue_filename, sizeof(cue_filename), "%s.cue", state->title);
strlcpy(cue_filename, state->title, sizeof(cue_filename));
strlcat(cue_filename, ".cue", sizeof(cue_filename));
fill_pathname_join(output_file,
directory_core_assets, cue_filename, sizeof(output_file));
@ -256,7 +255,7 @@ static void task_cdrom_dump_handler(retro_task_t *task)
char output_path[PATH_MAX_LENGTH];
char track_filename[PATH_MAX_LENGTH];
output_path[0] = track_filename[0] = '\0';
track_filename[0] = '\0';
snprintf(track_filename, sizeof(track_filename), "%s (Track %02d).bin", state->title, state->cur_track);
@ -265,9 +264,7 @@ static void task_cdrom_dump_handler(retro_task_t *task)
fill_pathname_join(output_path,
directory_core_assets, track_filename, sizeof(output_path));
state->output_file = filestream_open(output_path, RETRO_VFS_FILE_ACCESS_WRITE, 0);
if (!state->output_file)
if (!(state->output_file = filestream_open(output_path, RETRO_VFS_FILE_ACCESS_WRITE, 0)))
{
RARCH_ERR("[CDROM]: Error opening file for writing: %s\n", output_path);
task_set_progress(task, 100);

View File

@ -277,7 +277,6 @@ static void task_core_backup_handler(retro_task_t *task)
char task_title[PATH_MAX_LENGTH];
char backup_path[PATH_MAX_LENGTH];
task_title[0] = '\0';
backup_path[0] = '\0';
/* Get backup path */
@ -415,8 +414,6 @@ static void task_core_backup_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Get number of old backups to remove */
backup_handle->num_auto_backups_to_remove = num_backups -
backup_handle->auto_backup_history_size;
@ -483,19 +480,18 @@ static void task_core_backup_handler(retro_task_t *task)
case CORE_BACKUP_END:
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Set final task title */
task_free_title(task);
if (backup_handle->success)
{
if (backup_handle->crc_match)
strlcpy(task_title, msg_hash_to_str(MSG_CORE_BACKUP_ALREADY_EXISTS),
strlcpy(task_title,
msg_hash_to_str(MSG_CORE_BACKUP_ALREADY_EXISTS),
sizeof(task_title));
else
strlcpy(task_title, msg_hash_to_str(MSG_CORE_BACKUP_COMPLETE),
strlcpy(task_title,
msg_hash_to_str(MSG_CORE_BACKUP_COMPLETE),
sizeof(task_title));
}
else
@ -540,8 +536,6 @@ void *task_push_core_backup(
core_backup_handle_t *backup_handle = NULL;
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Sanity check */
if (string_is_empty(core_path) ||
!path_is_valid(core_path))
@ -577,9 +571,8 @@ void *task_push_core_backup(
}
/* Configure handle */
backup_handle = (core_backup_handle_t*)calloc(1, sizeof(core_backup_handle_t));
if (!backup_handle)
if (!(backup_handle = (core_backup_handle_t*)calloc(1,
sizeof(core_backup_handle_t))))
goto error;
backup_handle->dir_core_assets = string_is_empty(dir_core_assets) ? NULL : strdup(dir_core_assets);
@ -604,9 +597,7 @@ void *task_push_core_backup(
backup_handle->status = CORE_BACKUP_BEGIN;
/* Create task */
task = task_init();
if (!task)
if (!(task = task_init()))
goto error;
/* Get initial task title */
@ -667,9 +658,7 @@ static void task_core_restore_handler(retro_task_t *task)
if (!task)
goto task_finished;
backup_handle = (core_backup_handle_t*)task->state;
if (!backup_handle)
if (!(backup_handle = (core_backup_handle_t*)task->state))
goto task_finished;
if (task_get_cancelled(task))
@ -750,8 +739,6 @@ static void task_core_restore_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Open backup file */
#if defined(HAVE_ZLIB)
backup_handle->backup_file = intfstream_open_rzip_file(
@ -885,8 +872,6 @@ static void task_core_restore_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Set final task title */
task_free_title(task);
@ -941,13 +926,12 @@ bool task_push_core_restore(const char *backup_path, const char *dir_libretro,
char task_title[256];
core_path[0] = '\0';
task_title[0] = '\0';
/* Sanity check */
if (string_is_empty(backup_path) ||
!path_is_valid(backup_path) ||
string_is_empty(dir_libretro) ||
!core_loaded)
if ( string_is_empty(backup_path)
|| !path_is_valid(backup_path)
|| string_is_empty(dir_libretro)
|| !core_loaded)
goto error;
/* Ensure core directory is valid */
@ -968,9 +952,6 @@ bool task_push_core_restore(const char *backup_path, const char *dir_libretro,
{
const char *backup_filename = path_basename(backup_path);
char msg[PATH_MAX_LENGTH];
msg[0] = '\0';
strlcpy(msg, msg_hash_to_str(MSG_CORE_RESTORATION_INVALID_CONTENT), sizeof(msg));
if (backup_filename)
strlcat(msg, backup_filename, sizeof(msg));
@ -999,9 +980,6 @@ bool task_push_core_restore(const char *backup_path, const char *dir_libretro,
if (core_info_get_core_lock(core_path, true))
{
char msg[PATH_MAX_LENGTH];
msg[0] = '\0';
strlcpy(msg,
(backup_type == CORE_BACKUP_TYPE_ARCHIVE)
? msg_hash_to_str(MSG_CORE_RESTORATION_DISABLED)

View File

@ -305,11 +305,8 @@ static void task_core_updater_get_list_handler(retro_task_t *task)
const char *net_buildbot_url =
settings->paths.network_buildbot_url;
buildbot_url[0] = '\0';
/* Reset core updater list */
core_updater_list_reset(list_handle->core_list);
/* Get core listing URL */
if (!settings)
goto task_finished;
@ -571,11 +568,8 @@ void cb_http_task_core_updater_download(
core_updater_download_handle_t *download_handle = NULL;
char output_dir[PATH_MAX_LENGTH];
output_dir[0] = '\0';
if (!data || !transf)
goto finish;
if (!data->data || string_is_empty(transf->path))
goto finish;
@ -749,8 +743,6 @@ static void task_core_updater_download_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Update task title */
task_free_title(task);
@ -815,8 +807,6 @@ static void task_core_updater_download_handler(retro_task_t *task)
file_transfer_t *transf = NULL;
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Configure file transfer object */
if (!(transf = (file_transfer_t*)calloc(1,
sizeof(file_transfer_t))))
@ -885,8 +875,6 @@ static void task_core_updater_download_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Update task title */
task_free_title(task);
@ -945,8 +933,6 @@ static void task_core_updater_download_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Set final task title */
task_free_title(task);
@ -1042,9 +1028,6 @@ void *task_push_core_updater_download(
if (!mute)
{
char msg[PATH_MAX_LENGTH];
msg[0] = '\0';
strlcpy(msg, msg_hash_to_str(MSG_CORE_UPDATE_DISABLED), sizeof(msg));
strlcat(msg, list_entry->display_name, sizeof(msg));
@ -1248,9 +1231,6 @@ static void task_update_installed_cores_handler(retro_task_t *task)
if (core_installed)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
strlcpy(
task_title, msg_hash_to_str(MSG_CHECKING_CORE),
sizeof(task_title));
@ -1345,9 +1325,6 @@ static void task_update_installed_cores_handler(retro_task_t *task)
else
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Update task title */
task_free_title(task);
@ -1766,15 +1743,14 @@ static void task_play_feature_delivery_core_install_handler(
char backup_core_path[PATH_MAX_LENGTH];
bool backup_successful = false;
backup_core_path[0] = '\0';
/* Have to create a backup, in case install
* process fails
* > Note: since only one install task can
* run at a time, a UID is not required */
/* Generate backup file name */
strlcpy(backup_core_path, pfd_install_handle->local_core_path,
strlcpy(backup_core_path,
pfd_install_handle->local_core_path,
sizeof(backup_core_path));
strlcat(backup_core_path, FILE_PATH_BACKUP_EXTENSION,
sizeof(backup_core_path));
@ -1818,15 +1794,11 @@ static void task_play_feature_delivery_core_install_handler(
break;
case PLAY_FEATURE_DELIVERY_INSTALL_WAIT:
{
bool install_active;
enum play_feature_delivery_install_status install_status;
unsigned install_progress;
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Get current install status */
install_active = play_feature_delivery_download_status(
bool install_active = play_feature_delivery_download_status(
&install_status, &install_progress);
/* In all cases, update task progress */
@ -1873,8 +1845,6 @@ static void task_play_feature_delivery_core_install_handler(
const char *msg_str = msg_hash_to_str(MSG_CORE_INSTALL_FAILED);
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Set final task title */
task_free_title(task);
@ -1953,8 +1923,6 @@ void *task_push_play_feature_delivery_core_install(
play_feature_delivery_install_handle_t *pfd_install_handle = (play_feature_delivery_install_handle_t*)
calloc(1, sizeof(play_feature_delivery_install_handle_t));
task_title[0] = '\0';
/* Sanity check */
if ( !core_list
|| string_is_empty(filename)
@ -2150,14 +2118,10 @@ static void task_play_feature_delivery_switch_cores_handler(
if (core_installed)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
strlcpy(task_title, msg_hash_to_str(MSG_CHECKING_CORE),
sizeof(task_title));
strlcat(task_title, list_entry->display_name,
sizeof(task_title));
task_set_title(task, strdup(task_title));
}
else
@ -2218,8 +2182,6 @@ static void task_play_feature_delivery_switch_cores_handler(
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Update task title */
task_free_title(task);

View File

@ -47,13 +47,9 @@ static int file_decompressed_subdir(const char *name,
char path[PATH_MAX_LENGTH];
size_t name_len = strlen(name);
char last_char = name[name_len - 1];
path_dir[0] = path[0] = '\0';
/* Ignore directories, go to next file. */
if (last_char == '/' || last_char == '\\')
return 1;
if (strstr(name, userdata->dec->subdir) != name)
return 1;
@ -89,13 +85,9 @@ static int file_decompressed(const char *name, const char *valid_exts,
decompress_state_t *dec = userdata->dec;
size_t name_len = strlen(name);
char last_char = name[name_len - 1];
path[0] = '\0';
/* Ignore directories, go to next file. */
if (last_char == '/' || last_char == '\\')
return 1;
/* Make directory */
fill_pathname_join(path, dec->target_dir, name, sizeof(path));
path_basedir_wrapper(path);

View File

@ -305,8 +305,6 @@ static void task_manual_content_scan_handler(retro_task_t *task)
const char *entry_file_ext = NULL;
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Update progress display */
task_free_title(task);
@ -369,8 +367,6 @@ static void task_manual_content_scan_handler(retro_task_t *task)
char task_title[PATH_MAX_LENGTH];
const char *content_file = path_basename(content_path);
task_title[0] = '\0';
/* Update progress display */
task_free_title(task);
@ -430,8 +426,6 @@ static void task_manual_content_scan_handler(retro_task_t *task)
const char *m3u_name = path_basename_nocompression(m3u_path);
m3u_file_t *m3u_file = NULL;
task_title[0] = '\0';
/* Update progress display */
task_free_title(task);
@ -477,8 +471,6 @@ static void task_manual_content_scan_handler(retro_task_t *task)
{
char task_title[PATH_MAX_LENGTH];
task_title[0] = '\0';
/* Ensure playlist is alphabetically sorted
* > Override user settings here */
playlist_set_sort_mode(manual_scan->playlist, PLAYLIST_SORT_MODE_DEFAULT);
@ -535,8 +527,6 @@ bool task_push_manual_content_scan(
retro_task_t *task = NULL;
manual_scan_handle_t *manual_scan = NULL;
task_title[0] = '\0';
/* Sanity check */
if ( !playlist_config
|| string_is_empty(playlist_directory))

View File

@ -100,7 +100,6 @@ static bool get_thumbnail_paths(
const char *system_name = NULL;
content_dir[0] = '\0';
tmp_buf[0] = '\0';
if (!pl_thumb->thumbnail_path_data)
return false;

View File

@ -206,8 +206,6 @@ static void task_pl_manager_reset_cores_handler(retro_task_t *task)
else if (!string_is_empty(entry->path))
{
char entry_name[PATH_MAX_LENGTH];
entry_name[0] = '\0';
fill_pathname_base(entry_name, entry->path, sizeof(entry_name));
path_remove_extension(entry_name);
strlcat(task_title, entry_name, sizeof(task_title));
@ -286,13 +284,9 @@ bool task_push_pl_manager_reset_cores(const playlist_config_t *playlist_config)
retro_task_t *task = task_init();
pl_manager_handle_t *pl_manager = (pl_manager_handle_t*)
calloc(1, sizeof(pl_manager_handle_t));
playlist_name[0] = '\0';
/* Sanity check */
if (!playlist_config || !task || !pl_manager)
goto error;
if (string_is_empty(playlist_config->path))
goto error;
@ -712,13 +706,9 @@ bool task_push_pl_manager_clean_playlist(
retro_task_t *task = task_init();
pl_manager_handle_t *pl_manager = (pl_manager_handle_t*)
calloc(1, sizeof(pl_manager_handle_t));
playlist_name[0] = '\0';
/* Sanity check */
if (!playlist_config || !task || !pl_manager)
goto error;
if (string_is_empty(playlist_config->path))
goto error;

View File

@ -282,9 +282,6 @@ static bool screenshot_dump(
!string_is_empty(content_dir))
{
char content_dir_name[PATH_MAX_LENGTH];
content_dir_name[0] = '\0';
fill_pathname_parent_dir_name(content_dir_name,
content_dir, sizeof(content_dir_name));
fill_pathname_join(