Skip to content

Commit 5299276

Browse files
committed
win32: Prevent broken substitution string when variable is undefined
Avoids an issue where `%undefined:A=B%` expands to a literal `A=B` because the parser fails to find the variable before the colon, then parses the following percent as the next variable expansion. Added a definition check to ensure safe expansion.
1 parent b5ecfd1 commit 5299276

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

win32/configure.bat

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ for /f "delims== tokens=1,*" %%I in ("%~1") do ((set "opt=%%I") && (set "arg=%%J
6666
set "var=%opt%"
6767
goto :name
6868
)
69-
set "target=%opt%"
70-
echo>>%confargs% "--target=%opt:$=$$%" \
69+
set "arg=%opt%"
70+
set "eq=="
71+
set "opt=--target"
72+
set "target=%arg%"
73+
:loopend
74+
if not "%arg%" == "" (
75+
echo>>%confargs% "%opt%=%arg:$=$$%" \
76+
) else (
77+
echo>>%confargs% "%opt%%eq%" \
78+
)
7179
goto :loop ;
7280
:target
7381
if "%eq%" == "" (set "arg=%~1" & shift)
@@ -76,6 +84,7 @@ goto :loop ;
7684
exit /b 1
7785
)
7886
set "target=%arg%"
87+
set "opt=--target"
7988
echo>>%confargs% "--target=%arg:$=$$%" \
8089
goto :loop ;
8190
:program_name
@@ -92,13 +101,11 @@ goto :unknown_opt
92101
:name
93102
if "%eq%" == "" (set "arg=%~1" & shift)
94103
echo>> %config_make% %var% = %arg%
95-
echo>>%confargs% "%opt%=%arg:$=$$%" \
96-
goto :loop ;
104+
goto :loopend ;
97105
:dir
98106
if "%eq%" == "" (set "arg=%~1" & shift)
99107
echo>> %config_make% %opt:~2% = %arg:\=/%
100-
echo>>%confargs% "%opt%=%arg:$=$$%" \
101-
goto :loop ;
108+
goto :loopend ;
102109
:enable
103110
echo>>%confargs% "%opt%" \
104111
if %enable% == yes (set "opt=%opt:~9%") else (set "opt=%opt:~10%")
@@ -128,7 +135,11 @@ goto :loop ;
128135
:witharg
129136
if "%opt%" == "--with-static-linked-ext" goto :extstatic
130137
if "%eq%" == "" (set "arg=%~1" & shift)
131-
echo>>%confargs% "%opt%=%arg:$=$$%" \
138+
if not "%arg%" == "" (
139+
echo>>%confargs% "%opt%=%arg:$=$$%" \
140+
) else (
141+
echo>>%confargs% "%opt%%eq%" \
142+
)
132143
if "%opt%" == "--with-baseruby" goto :baseruby
133144
if "%opt%" == "--with-ntver" goto :ntver
134145
if "%opt%" == "--with-libdir" goto :libdir
@@ -149,23 +160,19 @@ goto :loop ;
149160
call set NTVER=_WIN32_WINNT_%%NTVER%%
150161
)
151162
echo>> %config_make% NTVER = %NTVER%
152-
echo>>%confargs% "%opt%=%arg:$=$$%" \
153-
goto :loop ;
163+
goto :loopend ;
154164
:extout
155165
if "%eq%" == "" (set "arg=%~1" & shift)
156166
if not "%arg%" == ".ext" (echo>> %config_make% EXTOUT = %arg%)
157-
echo>>%confargs% "%opt%=%arg:$=$$%" \
158-
goto :loop ;
167+
goto :loopend ;
159168
:path
160169
if "%eq%" == "" (set "arg=%~1" & shift)
161170
set "pathlist=%pathlist%%arg:\=/%;"
162-
echo>>%confargs% "%opt%=%arg:$=$$%" \
163-
goto :loop ;
171+
goto :loopend ;
164172
:extstatic
165173
if "%eq%" == "" (set "arg=static" & shift)
166174
echo>> %config_make% EXTSTATIC = %arg%
167-
echo>>%confargs% "%opt%=%arg:$=$$%" \
168-
goto :loop ;
175+
goto :loopend ;
169176
:baseruby
170177
echo>> %config_make% HAVE_BASERUBY = yes
171178
echo>> %config_make% BASERUBY = %arg%

0 commit comments

Comments
 (0)