tools: env validate: pass values as 0-based array
passing argv/argc can produce off-by-one errors Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
This commit is contained in:
parent
57dc53a724
commit
167f525871
@ -373,21 +373,21 @@ int env_flags_validate_varaccess(const char *name, int check_mask)
|
||||
/*
|
||||
* Validate the parameters to "env set" directly
|
||||
*/
|
||||
int env_flags_validate_env_set_params(int argc, char * const argv[])
|
||||
int env_flags_validate_env_set_params(char *name, char * const val[], int count)
|
||||
{
|
||||
if ((argc >= 3) && argv[2] != NULL) {
|
||||
enum env_flags_vartype type = env_flags_get_type(argv[1]);
|
||||
if ((count >= 1) && val[0] != NULL) {
|
||||
enum env_flags_vartype type = env_flags_get_type(name);
|
||||
|
||||
/*
|
||||
* we don't currently check types that need more than
|
||||
* one argument
|
||||
*/
|
||||
if (type != env_flags_vartype_string && argc > 3) {
|
||||
printf("## Error: too many parameters for setting "
|
||||
"\"%s\"\n", argv[1]);
|
||||
if (type != env_flags_vartype_string && count > 1) {
|
||||
printf("## Error: too many parameters for setting \"%s\"\n",
|
||||
name);
|
||||
return -1;
|
||||
}
|
||||
return env_flags_validate_type(argv[1], argv[2]);
|
||||
return env_flags_validate_type(name, val[0]);
|
||||
}
|
||||
/* ok */
|
||||
return 0;
|
||||
|
@ -143,7 +143,7 @@ int env_flags_validate_varaccess(const char *name, int check_mask);
|
||||
/*
|
||||
* Validate the parameters passed to "env set" for type compliance
|
||||
*/
|
||||
int env_flags_validate_env_set_params(int argc, char * const argv[]);
|
||||
int env_flags_validate_env_set_params(char *name, char *const val[], int count);
|
||||
|
||||
#else /* !USE_HOSTCC */
|
||||
|
||||
|
11
tools/env/fw_env.c
vendored
11
tools/env/fw_env.c
vendored
@ -498,8 +498,9 @@ int fw_setenv(int argc, char *argv[])
|
||||
{
|
||||
int i, rc;
|
||||
size_t len;
|
||||
char *name;
|
||||
char *name, **valv;
|
||||
char *value = NULL;
|
||||
int valc;
|
||||
|
||||
#ifdef CONFIG_FILE
|
||||
if (argc >= 2 && strcmp(argv[1], "-c") == 0) {
|
||||
@ -543,13 +544,15 @@ int fw_setenv(int argc, char *argv[])
|
||||
}
|
||||
|
||||
name = argv[1];
|
||||
valv = argv + 2;
|
||||
valc = argc - 2;
|
||||
|
||||
if (env_flags_validate_env_set_params(argc, argv) < 0)
|
||||
if (env_flags_validate_env_set_params(name, valv, valc) < 0)
|
||||
return 1;
|
||||
|
||||
len = 0;
|
||||
for (i = 2; i < argc; ++i) {
|
||||
char *val = argv[i];
|
||||
for (i = 0; i < valc; ++i) {
|
||||
char *val = valv[i];
|
||||
size_t val_len = strlen(val);
|
||||
|
||||
if (value)
|
||||
|
Loading…
Reference in New Issue
Block a user