]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cmdline] Fix multi-layer variable expansion (again)
authorMichael Brown <mcb30@ipxe.org>
Tue, 23 Nov 2010 00:18:11 +0000 (00:18 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 23 Nov 2010 00:18:11 +0000 (00:18 +0000)
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>
src/core/exec.c

index 18fc57f5c6510146652f450e5b5e0b4ae89d9125..d96b8a768ab8d59571162c3a77957ca5529fd417 100644 (file)
@@ -121,12 +121,12 @@ static char * expand_command ( const char *command ) {
                for ( tmp = expcmd ; *tmp ; tmp++ ) {
                        if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
                                start = tmp;
-                       if ( tmp[0] == '}' )
+                       if ( start && ( tmp[0] == '}' ) ) {
                                end = tmp;
-                       if ( start && end )
                                break;
+                       }
                }
-               if ( ! ( start && end ) )
+               if ( ! end )
                        break;
                *start = '\0';
                name = ( start + 2 );