Explorar el Código

[settings] Use concat_args() in "set" command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown hace 13 años
padre
commit
aebba8f6eb
Se han modificado 2 ficheros con 21 adiciones y 24 borrados
  1. 20
    24
      src/hci/commands/nvo_cmd.c
  2. 1
    0
      src/include/ipxe/errfile.h

+ 20
- 24
src/hci/commands/nvo_cmd.c Ver fichero

@@ -99,42 +99,38 @@ static struct command_descriptor set_cmd =
99 99
 static int set_exec ( int argc, char **argv ) {
100 100
 	struct set_options opts;
101 101
 	const char *name;
102
-	size_t len;
103
-	int i;
102
+	char *value;
104 103
 	int rc;
105 104
 
106 105
 	/* Parse options */
107 106
 	if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
108
-		return rc;
107
+		goto err_parse_options;
109 108
 
110 109
 	/* Parse setting name */
111 110
 	name = argv[optind];
112 111
 
113
-	/* Determine total length of command line */
114
-	len = 1; /* NUL */
115
-	for ( i = optind + 1 ; i < argc ; i++ )
116
-		len += ( 1 /* possible space */ + strlen ( argv[i] ) );
112
+	/* Parse setting value */
113
+	value = concat_args ( &argv[ optind + 1 ] );
114
+	if ( ! value ) {
115
+		rc = -ENOMEM;
116
+		goto err_concat_args;
117
+	}
117 118
 
118
-	{
119
-		char buf[len];
120
-		char *ptr = buf;
121
-
122
-		/* Assemble command line */
123
-		buf[0] = '\0';
124
-		for ( i = optind + 1 ; i < argc ; i++ ) {
125
-			ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
126
-					 argv[i] );
127
-		}
128
-		assert ( ptr < ( buf + len ) );
129
-
130
-		if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) {
131
-			printf ( "Could not set \"%s\"=\"%s\": %s\n",
132
-				 name, buf, strerror ( rc ) );
133
-			return rc;
134
-		}
119
+	/* Determine total length of command line */
120
+	if ( ( rc = storef_named_setting ( name, value ) ) != 0 ) {
121
+		printf ( "Could not set \"%s\"=\"%s\": %s\n",
122
+			 name, value, strerror ( rc ) );
123
+		goto err_store;
135 124
 	}
136 125
 
126
+	free ( value );
137 127
 	return 0;
128
+
129
+ err_store:
130
+	free ( value );
131
+ err_concat_args:
132
+ err_parse_options:
133
+	return rc;
138 134
 }
139 135
 
140 136
 /** "clear" options */

+ 1
- 0
src/include/ipxe/errfile.h Ver fichero

@@ -238,6 +238,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
238 238
 #define ERRFILE_sanboot_cmd	      ( ERRFILE_OTHER | 0x00200000 )
239 239
 #define ERRFILE_bofm		      ( ERRFILE_OTHER | 0x00210000 )
240 240
 #define ERRFILE_prompt		      ( ERRFILE_OTHER | 0x00220000 )
241
+#define ERRFILE_nvo_cmd		      ( ERRFILE_OTHER | 0x00230000 )
241 242
 
242 243
 /** @} */
243 244
 

Loading…
Cancelar
Guardar