Prefer using snprintf instead of insecure sprintf

pull/12413/head
twinaphex 2021-05-18 15:14:08 +02:00
parent b037da7264
commit 7bbdd6d18a
5 changed files with 16 additions and 10 deletions

View File

@ -129,7 +129,7 @@ void scope_repeat(scope_t *scope)
gen->value.val_dec = (float)((int)gen->value.val_dec << gen->shift);
else if (gen->shift < 0)
gen->value.val_dec = (float)((int)gen->value.val_dec >> -gen->shift);
sprintf(tmp, "%f", gen->value.val_dec);
snprintf(tmp, sizeof(tmp), "%f", gen->value.val_dec);
}
else
{
@ -138,7 +138,7 @@ void scope_repeat(scope_t *scope)
gen->value.val_int <<= gen->shift;
else if (gen->shift < 0)
gen->value.val_int >>= -gen->shift;
sprintf(tmp, "%d", gen->value.val_int);
snprintf(tmp, sizeof(tmp), "%d", gen->value.val_int);
}
string_set(&param->value, tmp);

View File

@ -1235,7 +1235,13 @@ chd_error chd_get_metadata(chd_file *chd, UINT32 searchtag, UINT32 searchindex,
UINT32 faux_length;
/* fill in the faux metadata */
sprintf(faux_metadata, HARD_DISK_METADATA_FORMAT, chd->header.obsolete_cylinders, chd->header.obsolete_heads, chd->header.obsolete_sectors, chd->header.hunkbytes / chd->header.obsolete_hunksize);
snprintf(faux_metadata,
sizeof(faux_metadata),
HARD_DISK_METADATA_FORMAT,
chd->header.obsolete_cylinders,
chd->header.obsolete_heads,
chd->header.obsolete_sectors,
chd->header.hunkbytes / chd->header.obsolete_hunksize);
faux_length = (UINT32)strlen(faux_metadata) + 1;
/* copy the metadata itself */

View File

@ -1025,7 +1025,7 @@ static int action_bind_sublabel_cpu_policy_entry_list(
int idx = atoi(path);
if (drivers)
{
sprintf(s, "%s | Freq: %u MHz\n", drivers[idx]->scaling_governor,
snprintf(s, len, "%s | Freq: %u MHz\n", drivers[idx]->scaling_governor,
drivers[idx]->current_frequency / 1000);
return 0;
}

View File

@ -10047,7 +10047,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
while (*drivers)
{
char policyid[16];
sprintf(policyid, "%u", count++);
snprintf(policyid, sizeof(policyid), "%u", count++);
menu_entries_append_enum(info->list,
policyid,
policyid,

View File

@ -197,9 +197,9 @@ bool set_cpu_scaling_min_frequency(
{
char fpath[PATH_MAX_LENGTH];
char value[16];
sprintf(fpath, CPU_POLICIES_DIR "policy%u/scaling_min_freq",
snprintf(fpath, sizeof(fpath), CPU_POLICIES_DIR "policy%u/scaling_min_freq",
driver->policy_id);
sprintf(value, "%" PRIu32 "\n", min_freq);
snprintf(value, sizeof(value), "%" PRIu32 "\n", min_freq);
if (filestream_write_file(fpath, value, strlen(value)))
{
driver->min_policy_freq = min_freq;
@ -215,9 +215,9 @@ bool set_cpu_scaling_max_frequency(
{
char fpath[PATH_MAX_LENGTH];
char value[16];
sprintf(fpath, CPU_POLICIES_DIR "policy%u/scaling_max_freq",
snprintf(fpath, sizeof(fpath), CPU_POLICIES_DIR "policy%u/scaling_max_freq",
driver->policy_id);
sprintf(value, "%" PRIu32 "\n", max_freq);
snprintf(value, sizeof(value), "%" PRIu32 "\n", max_freq);
if (filestream_write_file(fpath, value, strlen(value)))
{
driver->max_policy_freq = max_freq;
@ -294,7 +294,7 @@ uint32_t get_cpu_scaling_next_frequency_limit(uint32_t freq, int step)
bool set_cpu_scaling_governor(cpu_scaling_driver_t *driver, const char* governor)
{
char fpath[PATH_MAX_LENGTH];
sprintf(fpath, CPU_POLICIES_DIR "policy%u/scaling_governor",
snprintf(fpath, sizeof(fpath), CPU_POLICIES_DIR "policy%u/scaling_governor",
driver->policy_id);
if (filestream_write_file(fpath, governor, strlen(governor)))
{