Ver código fonte

[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 anos atrás
pai
commit
66679fe7df
1 arquivos alterados com 3 adições e 3 exclusões
  1. 3
    3
      src/core/exec.c

+ 3
- 3
src/core/exec.c Ver arquivo

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

Carregando…
Cancelar
Salvar