Removed limit on lenght of command line options.

In particular -f and -s options may contains paths that can easily
exceed the (old) 128 bytes buffer.

Change-Id: Ifc198536549f50663e8e588519bb9ef75dcd172c
Signed-off-by: Cristian Maglie <c.maglie@bug.st>
Reviewed-on: http://openocd.zylin.com/2241
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
This commit is contained in:
Cristian Maglie 2014-08-08 18:40:57 +02:00 committed by Andreas Fritiofson
parent 5587013ad6
commit 1fa24ebe39
1 changed files with 11 additions and 10 deletions

View File

@ -141,7 +141,6 @@ static void add_default_dirs(void)
int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[]) int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
{ {
int c; int c;
char command_buffer[128];
while (1) { while (1) {
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
@ -164,24 +163,26 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
break; break;
case 'f': /* --file | -f */ case 'f': /* --file | -f */
{ {
snprintf(command_buffer, 128, "script {%s}", optarg); char *command = alloc_printf("script {%s}", optarg);
add_config_command(command_buffer); add_config_command(command);
free(command);
break; break;
} }
case 's': /* --search | -s */ case 's': /* --search | -s */
add_script_search_dir(optarg); add_script_search_dir(optarg);
break; break;
case 'd': /* --debug | -d */ case 'd': /* --debug | -d */
if (optarg) {
snprintf(command_buffer, 128, "debug_level %s", optarg); char *command = alloc_printf("debug_level %s", optarg ? optarg : "3");
else command_run_line(cmd_ctx, command);
snprintf(command_buffer, 128, "debug_level 3"); free(command);
command_run_line(cmd_ctx, command_buffer);
break; break;
}
case 'l': /* --log_output | -l */ case 'l': /* --log_output | -l */
if (optarg) { if (optarg) {
snprintf(command_buffer, 128, "log_output %s", optarg); char *command = alloc_printf("log_output %s", optarg);
command_run_line(cmd_ctx, command_buffer); command_run_line(cmd_ctx, command);
free(command);
} }
break; break;
case 'c': /* --command | -c */ case 'c': /* --command | -c */