mirror of https://github.com/ipxe/ipxe.git
[cmdline] Fix multi-layer variable expansion
Expansion of ${${foo}} will currently fail, because the first opening "${" will be incorrectly matched against the first closing "}", leading to an attempt to expand the variable "${foo". Fix by ensuring that the most recent opening "${" is used to match against the first closing "}". Total cost: 8 bytes. :) Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
a180c7526c
commit
c1327e43ab
|
@ -115,17 +115,21 @@ static char * expand_command ( const char *command ) {
|
|||
|
||||
head = expcmd;
|
||||
|
||||
/* Locate opener */
|
||||
start = strstr ( expcmd, "${" );
|
||||
if ( ! start )
|
||||
/* Locate setting to be expanded */
|
||||
start = NULL;
|
||||
end = NULL;
|
||||
for ( tmp = expcmd ; *tmp ; tmp++ ) {
|
||||
if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
|
||||
start = tmp;
|
||||
if ( tmp[0] == '}' )
|
||||
end = tmp;
|
||||
if ( start && end )
|
||||
break;
|
||||
}
|
||||
if ( ! ( start && end ) )
|
||||
break;
|
||||
*start = '\0';
|
||||
name = ( start + 2 );
|
||||
|
||||
/* Locate closer */
|
||||
end = strstr ( name, "}" );
|
||||
if ( ! end )
|
||||
break;
|
||||
*end = '\0';
|
||||
tail = ( end + 1 );
|
||||
|
||||
|
|
Loading…
Reference in New Issue