checkwps: Validate %?St() tags

This will bail if referenced setting name does not exist.

Change-Id: I7abd54ec1260d3da6024ebec809f8e270b0a84e5
This commit is contained in:
Solomon Peachy 2025-09-27 10:15:28 -04:00
parent d57e1a21d1
commit d7d7627baf
6 changed files with 91 additions and 22 deletions

View file

@ -829,19 +829,12 @@ static int parse_setting_and_lang(struct skin_element *element,
}
else
{
/* NOTE: The string validations that happen here will
* automatically PASS on checkwps because its too hard to get
* settings_list.c built for a specific target.
* If that ever changes remove the #ifndef __PCTOOL__ here
*/
#ifndef __PCTOOL__
const struct settings_list *setting = find_setting_by_cfgname(temp);
if (!setting) {
DEBUGF("Invalid setting [%s]\n", temp);
return WPS_ERROR_INVALID_PARAM;
}
token->value.xdata = (void *)setting;
#endif
}
return 0;
}

View file

@ -21,18 +21,17 @@
#ifndef _ICONS_H_
#define _ICONS_H_
#ifndef PLUGIN
#if !defined(PLUGIN) && !defined(__PCTOOL__)
#include <lcd.h>
#include "metadata.h"
/* External bitmaps */
#include "bitmaps/rockboxlogo.h"
#ifdef HAVE_REMOTE_LCD
#include "bitmaps/remote_rockboxlogo.h"
#endif
#endif /* PLUGIN */
#endif /* !(PLUGIN || __PCTOOL__) */
struct cbmp_bitmap_info_entry /* */
{

View file

@ -76,11 +76,13 @@
#include "bootchart.h"
#include "scroll_engine.h"
#ifndef __PCTOOL__
struct user_settings global_settings;
struct system_status global_status;
static uint32_t user_settings_crc;
static long next_status_update_tick;
static long lasttime = 0;
#endif
/* flush system_status more often for spinning harddisks as we may not be able
* to spin up at shutdown in order to save so keep the gap minimal */
@ -106,6 +108,14 @@ static long lasttime = 0;
#include "usb-ibasso.h"
#endif
#ifdef LOGF_ENABLE
static char *debug_get_flags(uint32_t flags);
#undef DEBUGF /* allow DEBUGF or logf not both */
#define DEBUGF(...) do { } while(0)
#endif
#ifndef __PCTOOL__
#ifdef ROCKBOX_NO_TEMP_SETTINGS_FILE /* Overwrites same file each time */
#define CONFIGFILE_TEMP CONFIGFILE
#define RESUMEFILE_TEMP RESUMEFILE
@ -114,11 +124,6 @@ static long lasttime = 0;
#define CONFIGFILE_TEMP CONFIGFILE".new"
#define RESUMEFILE_TEMP RESUMEFILE".new"
#ifdef LOGF_ENABLE
static char *debug_get_flags(uint32_t flags);
#undef DEBUGF /* allow DEBUGF or logf not both */
#define DEBUGF(...) do { } while(0)
#endif
static void debug_available_settings(void);
static void rename_temp_file(const char *tempfile,
@ -1166,6 +1171,7 @@ const struct settings_list* find_setting(const void* variable)
return NULL;
}
#endif /* __PCTOOL__ */
const struct settings_list* find_setting_by_cfgname(const char* name)
{
@ -1187,6 +1193,7 @@ const struct settings_list* find_setting_by_cfgname(const char* name)
return NULL;
}
#ifndef __PCTOOL__
bool set_bool(const char* string, const bool* variable )
{
return set_bool_options(string, variable,
@ -1457,3 +1464,4 @@ static void debug_available_settings(void)
logf("End Available Settings\r\n");
#endif
}
#endif /* __PCTOOL__ */

View file

@ -80,7 +80,13 @@
#define BOOL(a) {.bool_ = a}
#define CHARPTR(a) {.charptr = a}
#define UCHARPTR(a) {.ucharptr = a}
#ifdef __PCTOOL__
#define FUNCTYPE(a) { }
#define lcd_set_contrast NULL
#define set_battery_capacity NULL
#else
#define FUNCTYPE(a) {.func = a}
#endif
#define NODEFAULT INT(0)
/* in all the following macros the args are:
@ -109,10 +115,17 @@
yes_id is the lang_id for the 'yes' (or 'on') option in the menu
no_id is the lang_id for the 'no' (or 'off') option in the menu
*/
#ifdef __PCTOOL_
#define BOOL_SETTING(flags,var,lang_id,default,name,cfgvals,yes_id,no_id,cb)\
{flags|F_BOOL_SETTING, &global_settings.var, \
lang_id, BOOL(default),name, \
{.bool_setting=(struct bool_setting[]){{cb,yes_id,no_id,cfgvals}}} }
#else
#define BOOL_SETTING(flags,var,lang_id,default,name,cfgvals,yes_id,no_id,cb)\
{flags|F_BOOL_SETTING, &global_settings.var, \
lang_id, BOOL(default),name, \
{.bool_setting=(struct bool_setting[]){{NULL,yes_id,no_id,cfgvals}}} }
#endif
/* bool setting which does use LANG_YES and _NO and save as "off,on" */
#define OFFON_SETTING(flags,var,lang_id,default,name,cb) \
@ -155,12 +168,21 @@
/* Used for settings which use the set_option() setting screen.
The ... arg is a list of pointers to strings to display in the setting
screen. These can either be literal strings, or ID2P(LANG_*) */
#ifdef __PCTOOL__
#define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \
{flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \
INT(default), name, \
{.choice_setting = (struct choice_setting[]){ \
{cb, count, cfg_vals, {.desc = (const unsigned char*[]) \
{NULL, count, cfg_vals, {.desc = (const unsigned char*[]) \
{__VA_ARGS__}}}}}}
#else
#define CHOICE_SETTING(flags,var,lang_id,default,name,cfg_vals,cb,count,...) \
{flags|F_CHOICE_SETTING|F_T_INT, &global_settings.var, lang_id, \
INT(default), name, \
{.choice_setting = (struct choice_setting[]){ \
{cb, count, cfg_vals, {.desc = (const unsigned char*[]) \
{__VA_ARGS__}}}}}}
#endif
/* Similar to above, except the strings to display are taken from cfg_vals,
the ... arg is a list of ID's to talk for the strings, can use TALK_ID()'s */
@ -176,6 +198,20 @@
unit is the UNIT_ define to display/talk.
the first one saves a string to the config file,
the second one saves the variable value to the config file */
#ifdef __PCTOOL__
#define INT_SETTING(flags, var, lang_id, default, name, \
unit, min, max, step, formatter, get_talk_id, cb) \
{flags|F_INT_SETTING|F_T_INT, &global_settings.var, \
lang_id, INT(default), name, \
{.int_setting = (struct int_setting[]){ \
{NULL, 0, step, min, max, NULL, NULL}}}}
#define INT_SETTING_NOWRAP(flags, var, lang_id, default, name, \
unit, min, max, step, formatter, get_talk_id, cb) \
{flags|F_INT_SETTING|F_T_INT|F_NO_WRAP, &global_settings.var, \
lang_id, INT(default), name, \
{.int_setting = (struct int_setting[]){ \
{NULL, 0, step, min, max, NULL, NULL}}}}
#else
#define INT_SETTING(flags, var, lang_id, default, name, \
unit, min, max, step, formatter, get_talk_id, cb) \
{flags|F_INT_SETTING|F_T_INT, &global_settings.var, \
@ -188,7 +224,16 @@
lang_id, INT(default), name, \
{.int_setting = (struct int_setting[]){ \
{cb, unit, step, min, max, formatter, get_talk_id}}}}
#endif
#ifdef __PCTOOL__
#define TABLE_SETTING(flags, var, lang_id, default, name, cfg_vals, \
unit, formatter, get_talk_id, cb, count, ...) \
{flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \
lang_id, INT(default), name, \
{.table_setting = (struct table_setting[]) { \
{NULL, NULL, NULL, 0, count, \
cfg_vals, (const int[]){__VA_ARGS__}}}}}
#else
#define TABLE_SETTING(flags, var, lang_id, default, name, cfg_vals, \
unit, formatter, get_talk_id, cb, count, ...) \
{flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \
@ -196,14 +241,32 @@
{.table_setting = (struct table_setting[]) { \
{cb, formatter, get_talk_id, unit, count, \
cfg_vals, (const int[]){__VA_ARGS__}}}}}
#endif /* __PCTOOL__ */
#ifdef __PCTOOL__
#define TABLE_SETTING_LIST(flags, var, lang_id, default, name, cfg_vals, \
unit, formatter, get_talk_id, cb, count, list) \
{flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \
lang_id, INT(default), name, \
{.table_setting = (struct table_setting[]) { \
{NULL, NULL, NULL, 0, count, cfg_vals, list}}}}
#else
#define TABLE_SETTING_LIST(flags, var, lang_id, default, name, cfg_vals, \
unit, formatter, get_talk_id, cb, count, list) \
{flags|F_TABLE_SETTING|F_T_INT, &global_settings.var, \
lang_id, INT(default), name, \
{.table_setting = (struct table_setting[]) { \
{cb, formatter, get_talk_id, unit, count, cfg_vals, list}}}}
#endif
#ifdef __PCTOOL__
#define CUSTOM_SETTING(flags, var, lang_id, default, name, \
load_from_cfg, write_to_cfg, \
is_change, set_default) \
{flags|F_CUSTOM_SETTING|F_T_CUSTOM|F_BANFROMQS, \
&global_settings.var, lang_id, \
{.custom = (void*)default}, name, \
{.custom_setting = (struct custom_setting[]){ \
{NULL, NULL, NULL, NULL}}}}
#else
#define CUSTOM_SETTING(flags, var, lang_id, default, name, \
load_from_cfg, write_to_cfg, \
is_change, set_default) \
@ -212,6 +275,7 @@
{.custom = (void*)default}, name, \
{.custom_setting = (struct custom_setting[]){ \
{load_from_cfg, write_to_cfg, is_change, set_default}}}}
#endif
#define VIEWPORT_SETTING(var,name) \
TEXT_SETTING(F_THEMESETTING|F_NEEDAPPLY,var,name,"-", NULL, NULL)
@ -394,6 +458,8 @@ static const char graphic_numeric[] = "graphic,numeric";
# define MAX_FILES_IN_DIR_STEP 50
#endif
#ifndef __PCTOOL__
#if LCD_DEPTH > 1
static const char* list_pad_formatter(char *buffer, size_t buffer_size,
int val, const char *unit)
@ -571,6 +637,7 @@ static int32_t get_precut_talkid(int value, int unit)
{
return TALK_ID_DECIMAL(-value, 1, unit);
}
#endif /* __PCTOOL__ */
struct eq_band_setting eq_defaults[EQ_NUM_BANDS] = {
{ 32, 7, 0 },
@ -585,6 +652,7 @@ struct eq_band_setting eq_defaults[EQ_NUM_BANDS] = {
{ 16000, 7, 0 },
};
#ifndef __PCTOOL__
static void eq_load_from_cfg(void *setting, char *value)
{
struct eq_band_setting *eq = setting;
@ -846,6 +914,8 @@ static void hp_lo_select_apply(int arg)
}
#endif
#endif /* __PCTOOL__ */
const struct settings_list settings[] = {
/* system_status settings .resume.cfg */
SYSTEM_STATUS_SOUND(F_NO_WRAP, volume, LANG_VOLUME, "volume", SOUND_VOLUME),

View file

@ -4,6 +4,8 @@
../../apps/gui/viewport.c
../../apps/language.c
../../apps/misc.c
../../apps/settings.c
../../apps/settings_list.c
../../firmware/common/strmemccpy.c
../../firmware/common/strlcpy.c
../../firmware/common/pathfuncs.c

View file

@ -39,9 +39,6 @@ bool debug_wps = false;
int wps_verbose_level = 0;
char *skin_buffer;
const struct settings_list *settings;
const int nb_settings = 0;
#ifdef SIMULATOR
#error beep beep
#endif