]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cmdline] Fix multi-layer variable expansion
authorMichael Brown <mcb30@ipxe.org>
Mon, 22 Nov 2010 21:31:00 +0000 (21:31 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 22 Nov 2010 21:34:35 +0000 (21:34 +0000)
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>
src/core/exec.c

index f65a4647c588602b7c28b56e1304743375243e09..18fc57f5c6510146652f450e5b5e0b4ae89d9125 100644 (file)
@@ -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 );