]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Eliminate variable-length stack allocation
authorMichael Brown <mcb30@ipxe.org>
Sun, 16 Feb 2020 22:30:38 +0000 (22:30 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 16 Feb 2020 22:30:38 +0000 (22:30 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/settings.c

index 3e5d416e7ba551c11ce636d564db5d24b271353d..430cdc84bc5508be87059a672d041ab6ce5930cb 100644 (file)
@@ -370,12 +370,14 @@ const char * settings_name ( struct settings *settings ) {
 static struct settings *
 parse_settings_name ( const char *name, get_child_settings_t get_child ) {
        struct settings *settings = &settings_root;
-       char name_copy[ strlen ( name ) + 1 ];
+       char *name_copy;
        char *subname;
        char *remainder;
 
        /* Create modifiable copy of name */
-       memcpy ( name_copy, name, sizeof ( name_copy ) );
+       name_copy = strdup ( name );
+       if ( ! name_copy )
+               return NULL;
        remainder = name_copy;
 
        /* Parse each name component in turn */
@@ -389,6 +391,9 @@ parse_settings_name ( const char *name, get_child_settings_t get_child ) {
                        break;
        }
 
+       /* Free modifiable copy of name */
+       free ( name_copy );
+
        return settings;
 }