summaryrefslogtreecommitdiffstats
path: root/src/core/exec.c
diff options
context:
space:
mode:
authorMichael Brown2010-11-22 22:31:00 +0100
committerMichael Brown2010-11-22 22:34:35 +0100
commitc1327e43ab4c9281651e8505a2149a96c11371b4 (patch)
tree9aba6931e639102dd580d198ea4047790a15400d /src/core/exec.c
parent[settings] Allow "set" command to take an empty value (diff)
downloadipxe-c1327e43ab4c9281651e8505a2149a96c11371b4.tar.gz
ipxe-c1327e43ab4c9281651e8505a2149a96c11371b4.tar.xz
ipxe-c1327e43ab4c9281651e8505a2149a96c11371b4.zip
[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>
Diffstat (limited to 'src/core/exec.c')
-rw-r--r--src/core/exec.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/exec.c b/src/core/exec.c
index f65a4647..18fc57f5 100644
--- a/src/core/exec.c
+++ b/src/core/exec.c
@@ -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 );