diff options
| author | Nameless <truemedian@gmail.com> | 2023-10-25 01:30:24 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-25 09:30:24 +0300 |
| commit | 6c9d34bce703b80562d86d08b71a92910fce1e46 (patch) | |
| tree | 0f74fd396dd18c356b544b08690fa9172a5c6816 /lib/std/Uri.zig | |
| parent | 22a6a5d93f000afd7e00450bb5a359f39bb598bf (diff) | |
| download | zig-6c9d34bce703b80562d86d08b71a92910fce1e46.tar.gz zig-6c9d34bce703b80562d86d08b71a92910fce1e46.zip | |
std.Uri: prevent crash with strange authority section
Diffstat (limited to 'lib/std/Uri.zig')
| -rw-r--r-- | lib/std/Uri.zig | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/std/Uri.zig b/lib/std/Uri.zig index 3f277d0cc6..b04731b427 100644 --- a/lib/std/Uri.zig +++ b/lib/std/Uri.zig @@ -171,6 +171,9 @@ pub fn parseWithoutScheme(text: []const u8) ParseError!Uri { } } + // only possible if uri consists of only `userinfo@` + if (start_of_host >= authority.len) break :a; + var end_of_host: usize = authority.len; if (authority[start_of_host] == '[') { // IPv6 @@ -565,6 +568,7 @@ test "authority" { try std.testing.expectEqualSlices(u8, "hostname", (try parse("scheme://userinfo@hostname")).host.?); try std.testing.expectEqualSlices(u8, "userinfo", (try parse("scheme://userinfo@hostname")).user.?); try std.testing.expectEqual(@as(?[]const u8, null), (try parse("scheme://userinfo@hostname")).password); + try std.testing.expectEqual(@as(?[]const u8, null), (try parse("scheme://userinfo@")).host); try std.testing.expectEqualSlices(u8, "hostname", (try parse("scheme://user:password@hostname")).host.?); try std.testing.expectEqualSlices(u8, "user", (try parse("scheme://user:password@hostname")).user.?); |
