Explorar el Código

[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 hace 13 años
padre
commit
66679fe7df
Se han modificado 1 ficheros con 3 adiciones y 3 borrados
  1. 3
    3
      src/core/exec.c

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

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

Loading…
Cancelar
Guardar