summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/pxe_utils.c6
-rw-r--r--common/cli_simple.c17
-rw-r--r--include/cli.h4
3 files changed, 19 insertions, 8 deletions
diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 235522f4bbc..b9d9a5786c2 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -322,7 +322,8 @@ static int label_localboot(struct pxe_label *label)
if (label->append) {
char bootargs[CONFIG_SYS_CBSIZE];
- cli_simple_process_macros(label->append, bootargs);
+ cli_simple_process_macros(label->append, bootargs,
+ sizeof(bootargs));
env_set("bootargs", bootargs);
}
@@ -430,7 +431,8 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
strcat(bootargs, ip_str);
strcat(bootargs, mac_str);
- cli_simple_process_macros(bootargs, finalbootargs);
+ cli_simple_process_macros(bootargs, finalbootargs,
+ sizeof(finalbootargs));
env_set("bootargs", finalbootargs);
printf("append: %s\n", finalbootargs);
}
diff --git a/common/cli_simple.c b/common/cli_simple.c
index 7d91316a0fb..e80ba488a5e 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -60,13 +60,14 @@ int cli_simple_parse_line(char *line, char *argv[])
return nargs;
}
-void cli_simple_process_macros(const char *input, char *output)
+int cli_simple_process_macros(const char *input, char *output, int max_size)
{
char c, prev;
const char *varname_start = NULL;
int inputcnt = strlen(input);
- int outputcnt = CONFIG_SYS_CBSIZE;
+ int outputcnt = max_size;
int state = 0; /* 0 = waiting for '$' */
+ int ret;
/* 1 = waiting for '(' or '{' */
/* 2 = waiting for ')' or '}' */
@@ -157,13 +158,18 @@ void cli_simple_process_macros(const char *input, char *output)
prev = c;
}
- if (outputcnt)
+ ret = inputcnt ? -ENOSPC : 0;
+ if (outputcnt) {
*output = 0;
- else
+ } else {
*(output - 1) = 0;
+ ret = -ENOSPC;
+ }
debug_parser("[PROCESS_MACROS] OUTPUT len %zd: \"%s\"\n",
strlen(output_start), output_start);
+
+ return ret;
}
/*
@@ -239,7 +245,8 @@ int cli_simple_run_command(const char *cmd, int flag)
debug_parser("token: \"%s\"\n", token);
/* find macros in this token and replace them */
- cli_simple_process_macros(token, finaltoken);
+ cli_simple_process_macros(token, finaltoken,
+ sizeof(finaltoken));
/* Extract arguments */
argc = cli_simple_parse_line(finaltoken, argv);
diff --git a/include/cli.h b/include/cli.h
index 39b913743b5..3449fa6ae72 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -34,8 +34,10 @@ int cli_simple_run_command(const char *cmd, int flag);
*
* @param input Input string possible containing $() / ${} vars
* @param output Output string with $() / ${} vars expanded
+ * @param max_size Maximum size of @output (including terminator)
+ * @return 0 if OK, -ENOSPC if we ran out of space in @output
*/
-void cli_simple_process_macros(const char *input, char *output);
+int cli_simple_process_macros(const char *input, char *output, int max_size);
/**
* cli_simple_run_command_list() - Execute a list of command