Skip to content

Commit

Permalink
envexec: add eligibility check for pipeMapping
Browse files Browse the repository at this point in the history
issue: #98
  • Loading branch information
criyle committed Mar 8, 2024
1 parent 4c53a0c commit f7327c0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ root = "."

[build]
cmd = "go build -o ./tmp/go-judge ./cmd/go-judge"
full_bin = "tmp/go-judge -enable-grpc -enable-debug -enable-metrics"
full_bin = "tmp/go-judge -enable-grpc -enable-debug -enable-metrics -http-addr=:5050 -grpc-addr=:5051"

include_ext = ["go"]
exclude_dir = ["dist"]
4 changes: 2 additions & 2 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ interface Cmd {
args: string[]; // 程序命令行参数
env?: string[]; // 程序环境变量

// 指定 标准输入、标准输出和标准错误的文件
files?: (LocalFile | MemoryFile | PreparedFile | Collector | StreamIn | StreamOut)[];
// 指定 标准输入、标准输出和标准错误的文件 (null 是为了 pipe 的使用情况准备的,而且必须被 pipeMapping 的 in / out 指定)
files?: (LocalFile | MemoryFile | PreparedFile | Collector | StreamIn | StreamOut | null)[];
tty?: boolean; // 开启 TTY (需要保证标准输出和标准错误为同一文件)同时需要指定 TERM 环境变量 (例如 TERM=xterm)

// 资源限制
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ interface Cmd {
args: string[]; // command line argument
env?: string[]; // environment

// specifies file input / pipe collector for program file descriptors
files?: (LocalFile | MemoryFile | PreparedFile | Collector | StreamIn | StreamOut)[];
// specifies file input / pipe collector for program file descriptors (null is reserved for pipe mapping and must be filled by in / out)
files?: (LocalFile | MemoryFile | PreparedFile | Collector | StreamIn | StreamOutnull)[];
tty?: boolean; // enables tty on the input and output pipes (should have just one input & one output)
// Notice: must have TERM environment variables (e.g. TERM=xterm)

Expand Down
15 changes: 15 additions & 0 deletions envexec/file_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ func prepareFds(r *Group, newStoreFile NewStoreFile) (f [][]*os.File, p [][]pipe

// prepare pipes
for _, p := range r.Pipes {
if files[p.Out.Index][p.Out.Fd] != nil {
return nil, nil, fmt.Errorf("pipe mapping to existing file descriptor: out %d/%d", p.Out.Index, p.Out.Fd)
}
if files[p.In.Index][p.In.Fd] != nil {
return nil, nil, fmt.Errorf("pipe mapping to existing file descriptor: in %d/%d", p.In.Index, p.In.Fd)
}
out, in, pc, err := pipe(p, newStoreFile)
if err != nil {
return nil, nil, err
Expand All @@ -254,6 +260,15 @@ func prepareFds(r *Group, newStoreFile NewStoreFile) (f [][]*os.File, p [][]pipe
pipeToCollect[p.In.Index] = append(pipeToCollect[p.In.Index], *pc)
}
}

// null check
for i, fds := range files {
for j, f := range fds {
if f == nil {
return nil, nil, fmt.Errorf("null passed to files for index/fd: %d/%d", i, j)
}
}
}
return files, pipeToCollect, nil
}

Expand Down

0 comments on commit f7327c0

Please sign in to comment.