跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

fuzz_test.go

36 行 · 975 B历史下载
1package runscript
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "strings"
8 "testing"
9)
10
11// The host picks a script's shell with Interpreter, the guest with
12// ShebangAWK: both must pick the same.
13func FuzzInterpreter(f *testing.F) {
14 if _, err := exec.LookPath("awk"); err != nil {
15 f.Skip("no awk")
16 }
17 for _, s := range []string{"#!/bin/bash\n", "#!/usr/bin/env -S bash -e\r\n", "#! /bin/sh -x", "#!/usr/bin/env FOO=1 zsh", "echo hi", "#!env\n", "#!/bin/bash\tx"} {
18 f.Add(s)
19 }
20 f.Fuzz(func(t *testing.T, s string) {
21 if strings.ContainsRune(s, 0) {
22 return
23 }
24 p := filepath.Join(t.TempDir(), "s")
25 if err := os.WriteFile(p, []byte(s), 0o644); err != nil {
26 t.Fatal(err)
27 }
28 out, err := exec.Command("awk", ShebangAWK, p).Output()
29 if err != nil {
30 return // input awk refuses (invalid bytes for its locale)
31 }
32 if g, a := Interpreter(s), strings.TrimSpace(string(out)); g != a {
33 t.Fatalf("Interpreter(%q) = %q, the guest's awk %q", s, g, a)
34 }
35 })
36}