Browse Source

[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>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
66679fe7df
1 changed files with 3 additions and 3 deletions
  1. 3
    3
      src/core/exec.c

+ 3
- 3
src/core/exec.c View File

121
 		for ( tmp = expcmd ; *tmp ; tmp++ ) {
121
 		for ( tmp = expcmd ; *tmp ; tmp++ ) {
122
 			if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
122
 			if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
123
 				start = tmp;
123
 				start = tmp;
124
-			if ( tmp[0] == '}' )
124
+			if ( start && ( tmp[0] == '}' ) ) {
125
 				end = tmp;
125
 				end = tmp;
126
-			if ( start && end )
127
 				break;
126
 				break;
127
+			}
128
 		}
128
 		}
129
-		if ( ! ( start && end ) )
129
+		if ( ! end )
130
 			break;
130
 			break;
131
 		*start = '\0';
131
 		*start = '\0';
132
 		name = ( start + 2 );
132
 		name = ( start + 2 );

Loading…
Cancel
Save