mirror of
https://github.com/ipxe/ipxe
synced 2025-12-22 04:50:25 +03:00
[cmdline] Fix multi-layer variable expansion (again)
Expansion of the (admittedly perverse) "aaa}bbb${ccc" will currently
fail because expand_command() does not check that the closing "}"
occurs later than the opening "${".
Fix by ensuring that the most recent opening "${" is used to match
against the first *subsequent* closing "}".
Total cost of this change: -12 bytes, bringing the overall cost of
this feature to -4 bytes.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -121,12 +121,12 @@ static char * expand_command ( const char *command ) {
|
|||||||
for ( tmp = expcmd ; *tmp ; tmp++ ) {
|
for ( tmp = expcmd ; *tmp ; tmp++ ) {
|
||||||
if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
|
if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
|
||||||
start = tmp;
|
start = tmp;
|
||||||
if ( tmp[0] == '}' )
|
if ( start && ( tmp[0] == '}' ) ) {
|
||||||
end = tmp;
|
end = tmp;
|
||||||
if ( start && end )
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( ! ( start && end ) )
|
}
|
||||||
|
if ( ! end )
|
||||||
break;
|
break;
|
||||||
*start = '\0';
|
*start = '\0';
|
||||||
name = ( start + 2 );
|
name = ( start + 2 );
|
||||||
|
|||||||
Reference in New Issue
Block a user