Skip to documentation
SLOP

tiny.sandbox.cwd

Reference tiny.sandbox cwd

Defined in tiny.sandbox.

API (2)

Actions

Public operations.

No direct callersNo direct callstiny.sandboxcwd
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callersprivate sourcelib.sandbox.src.cwdcontainsresolvedirPathcwdensureInside
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.sandbox.src.cwdtest: cwd rejects absolute and parent...cwdvalidate
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/sandbox/src/cwd.zig

zig
const std = @import("std");const sys = @import("sys");const resolve = @import("resolve.zig");pub fn validate(path: []const u8) !void {    if (path.len == 0) return error.InvalidCwd;    if (std.fs.path.isAbsolute(path)) return error.AbsoluteCwd;    var iterator = std.fs.path.componentIterator(path);    while (iterator.next()) |component| {        if (std.mem.eql(u8, component.name, "..")) return error.CwdEscapesLayer;    }}pub fn ensureInside(root: sys.fs.Dir, child: sys.fs.Dir) !void {    var root_buffer: [std.fs.max_path_bytes]u8 = undefined;    const root_path = try resolve.dirPath(root, &root_buffer);    var child_buffer: [std.fs.max_path_bytes]u8 = undefined;    const child_path = try resolve.dirPath(child, &child_buffer);    if (!contains(root_path, child_path)) return error.CwdEscapesLayer;}fn contains(root: []const u8, child: []const u8) bool {    if (std.mem.eql(u8, root, child)) return true;    if (root.len == 1 and root[0] == std.fs.path.sep) return std.fs.path.isAbsolute(child);    if (!std.mem.startsWith(u8, child, root)) return false;    if (child.len <= root.len) return false;    return child[root.len] == std.fs.path.sep;}test "cwd rejects absolute and parent paths" {    try std.testing.expectError(error.AbsoluteCwd, validate("/tmp"));    try std.testing.expectError(error.CwdEscapesLayer, validate("../tmp"));    try std.testing.expectError(error.CwdEscapesLayer, validate("sub/../tmp"));    try validate(".");    try validate("sub");}

Source: lib/sandbox/src/root.zig:35

zig
pub const cwd = @import("cwd.zig");

Audit

Definitions3
Public names3
Members0
Version26.7.0
Revisiondaab053ee433