From aebba8f6eb29ad41a4ed1b2dc821719b64f2b576 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Mar 2011 17:29:08 +0000 Subject: [PATCH] [settings] Use concat_args() in "set" command Signed-off-by: Michael Brown --- src/hci/commands/nvo_cmd.c | 46 +++++++++++++++++--------------------- src/include/ipxe/errfile.h | 1 + 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c index d8621abc..35c9d473 100644 --- a/src/hci/commands/nvo_cmd.c +++ b/src/hci/commands/nvo_cmd.c @@ -99,42 +99,38 @@ static struct command_descriptor set_cmd = static int set_exec ( int argc, char **argv ) { struct set_options opts; const char *name; - size_t len; - int i; + char *value; int rc; /* Parse options */ if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 ) - return rc; + goto err_parse_options; /* Parse setting name */ name = argv[optind]; - /* Determine total length of command line */ - len = 1; /* NUL */ - for ( i = optind + 1 ; i < argc ; i++ ) - len += ( 1 /* possible space */ + strlen ( argv[i] ) ); - - { - char buf[len]; - char *ptr = buf; - - /* Assemble command line */ - buf[0] = '\0'; - for ( i = optind + 1 ; i < argc ; i++ ) { - ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ), - argv[i] ); - } - assert ( ptr < ( buf + len ) ); - - if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) { - printf ( "Could not set \"%s\"=\"%s\": %s\n", - name, buf, strerror ( rc ) ); - return rc; - } + /* Parse setting value */ + value = concat_args ( &argv[ optind + 1 ] ); + if ( ! value ) { + rc = -ENOMEM; + goto err_concat_args; } + /* Determine total length of command line */ + if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) { + printf ( "Could not set \"%s\"=\"%s\": %s\n", + name, value, strerror ( rc ) ); + goto err_store; + } + + free ( value ); return 0; + + err_store: + free ( value ); + err_concat_args: + err_parse_options: + return rc; } /** "clear" options */ diff --git a/src/include/ipxe/errfile.h b/src/include/ipxe/errfile.h index 7968c4f5..3073383b 100644 --- a/src/include/ipxe/errfile.h +++ b/src/include/ipxe/errfile.h @@ -238,6 +238,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define ERRFILE_sanboot_cmd ( ERRFILE_OTHER | 0x00200000 ) #define ERRFILE_bofm ( ERRFILE_OTHER | 0x00210000 ) #define ERRFILE_prompt ( ERRFILE_OTHER | 0x00220000 ) +#define ERRFILE_nvo_cmd ( ERRFILE_OTHER | 0x00230000 ) /** @} */