From aadd1b252e1d912e45cc924a15872d7c3d1f9080 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Fri, 30 Dec 2022 22:09:31 -0800 Subject: [PATCH] ChildProcess: fix false positives in windowsCreateProcessSupportsExtension Previously, the implementation would essentially check `startsWith` instead of `eql` (e.g. it would return true for `.exec` because it erroneously 'matched' `.exe`). Follow up to #13993 --- lib/std/child_process.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 7bff9fe089..4a816c8318 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -1357,6 +1357,7 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 /// Case-insenstive UTF-16 lookup fn windowsCreateProcessSupportsExtension(ext: []const u16) bool { + if (ext.len != 4) return false; const State = enum { start, dot, @@ -1413,6 +1414,11 @@ fn windowsCreateProcessSupportsExtension(ext: []const u16) bool { return false; } +test "windowsCreateProcessSupportsExtension" { + try std.testing.expect(windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e' })); + try std.testing.expect(!windowsCreateProcessSupportsExtension(&[_]u16{ '.', 'e', 'X', 'e', 'c' })); +} + /// Caller must dealloc. fn windowsCreateCommandLine(allocator: mem.Allocator, argv: []const []const u8) ![:0]u8 { var buf = std.ArrayList(u8).init(allocator);