Browse Source

[settings] Eliminate variable-length stack allocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
master
Michael Brown 4 years ago
parent
commit
446e8f14e8
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      src/core/settings.c

+ 7
- 2
src/core/settings.c View File

@@ -370,12 +370,14 @@ const char * settings_name ( struct settings *settings ) {
370 370
 static struct settings *
371 371
 parse_settings_name ( const char *name, get_child_settings_t get_child ) {
372 372
 	struct settings *settings = &settings_root;
373
-	char name_copy[ strlen ( name ) + 1 ];
373
+	char *name_copy;
374 374
 	char *subname;
375 375
 	char *remainder;
376 376
 
377 377
 	/* Create modifiable copy of name */
378
-	memcpy ( name_copy, name, sizeof ( name_copy ) );
378
+	name_copy = strdup ( name );
379
+	if ( ! name_copy )
380
+		return NULL;
379 381
 	remainder = name_copy;
380 382
 
381 383
 	/* Parse each name component in turn */
@@ -389,6 +391,9 @@ parse_settings_name ( const char *name, get_child_settings_t get_child ) {
389 391
 			break;
390 392
 	}
391 393
 
394
+	/* Free modifiable copy of name */
395
+	free ( name_copy );
396
+
392 397
 	return settings;
393 398
 }
394 399
 

Loading…
Cancel
Save