Skip to content

Commit e0a3781

Browse files
M299/backport 5852 (#2405)
* set env in ProcessInvoker sanitized (#2280) * set env in ProcessInvoker sanitized * Update runnerversion and rel notes and make it prerelase --------- Co-authored-by: Stefan Ruvceski <[email protected]>
1 parent 2e44f98 commit e0a3781

File tree

5 files changed

+82
-1
lines changed

5 files changed

+82
-1
lines changed

.github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ jobs:
301301
release_name: "v${{ steps.releaseNote.outputs.version }}"
302302
body: |
303303
${{ steps.releaseNote.outputs.note }}
304+
prerelease: true
304305

305306
# Upload release assets (full runner packages)
306307
- name: Upload Release Asset (win-x64)

releaseNote.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
## Bugs
99
- Use Global.Variables instead of JobContext and include action path/ref in the message. (#2214)
10+
- Sanitize Windows ENVs (#2280)
1011

1112
## Misc
1213
- Allow '--disableupdate' in create-latest-svc.sh (#2201)

src/Runner.Sdk/ProcessInvoker.cs

+10
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,17 @@ public async Task<int> ExecuteAsync(
264264
{
265265
foreach (KeyValuePair<string, string> kvp in environment)
266266
{
267+
#if OS_WINDOWS
268+
string tempKey = String.IsNullOrWhiteSpace(kvp.Key) ? kvp.Key : kvp.Key.Split('\0')[0];
269+
string tempValue = String.IsNullOrWhiteSpace(kvp.Value) ? kvp.Value : kvp.Value.Split('\0')[0];
270+
if(!String.IsNullOrWhiteSpace(tempKey))
271+
{
272+
_proc.StartInfo.Environment[tempKey] = tempValue;
273+
}
274+
#else
267275
_proc.StartInfo.Environment[kvp.Key] = kvp.Value;
276+
277+
#endif
268278
}
269279
}
270280

src/Test/L0/ProcessInvokerL0.cs

+69
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,76 @@ public async Task SetCIEnv()
128128
}
129129
}
130130
}
131+
#if OS_WINDOWS
132+
[Fact]
133+
[Trait("Level", "L0")]
134+
[Trait("Category", "Common")]
135+
public async Task SetTestEnvWithNullInKey()
136+
{
137+
using (TestHostContext hc = new(this))
138+
{
139+
Tracing trace = hc.GetTrace();
140+
141+
Int32 exitCode = -1;
142+
var processInvoker = new ProcessInvokerWrapper();
143+
processInvoker.Initialize(hc);
144+
var stdout = new List<string>();
145+
var stderr = new List<string>();
146+
processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
147+
{
148+
trace.Info(e.Data);
149+
stdout.Add(e.Data);
150+
};
151+
processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
152+
{
153+
trace.Info(e.Data);
154+
stderr.Add(e.Data);
155+
};
156+
157+
exitCode = await processInvoker.ExecuteAsync("", "cmd.exe", "/c \"echo %TEST%\"", new Dictionary<string, string>() { { "TEST\0second", "first" } }, CancellationToken.None);
158+
159+
160+
trace.Info("Exit Code: {0}", exitCode);
161+
Assert.Equal(0, exitCode);
162+
Assert.Equal("first", stdout.First(x => !string.IsNullOrWhiteSpace(x)));
163+
164+
}
165+
}
131166

167+
[Fact]
168+
[Trait("Level", "L0")]
169+
[Trait("Category", "Common")]
170+
public async Task SetTestEnvWithNullInValue()
171+
{
172+
using (TestHostContext hc = new(this))
173+
{
174+
Tracing trace = hc.GetTrace();
175+
176+
Int32 exitCode = -1;
177+
var processInvoker = new ProcessInvokerWrapper();
178+
processInvoker.Initialize(hc);
179+
var stdout = new List<string>();
180+
var stderr = new List<string>();
181+
processInvoker.OutputDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
182+
{
183+
trace.Info(e.Data);
184+
stdout.Add(e.Data);
185+
};
186+
processInvoker.ErrorDataReceived += (object sender, ProcessDataReceivedEventArgs e) =>
187+
{
188+
trace.Info(e.Data);
189+
stderr.Add(e.Data);
190+
};
191+
192+
exitCode = await processInvoker.ExecuteAsync("", "cmd.exe", "/c \"echo %TEST%\"", new Dictionary<string, string>() { { "TEST", "first\0second" } }, CancellationToken.None);
193+
194+
trace.Info("Exit Code: {0}", exitCode);
195+
Assert.Equal(0, exitCode);
196+
Assert.Equal("first", stdout.First(x => !string.IsNullOrWhiteSpace(x)));
197+
198+
}
199+
}
200+
#endif
132201
[Fact]
133202
[Trait("Level", "L0")]
134203
[Trait("Category", "Common")]

src/runnerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.299.1
1+
2.299.2

0 commit comments

Comments
 (0)