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>
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 );