Skip to content

Commit f7327c0

Browse files
committed
envexec: add eligibility check for pipeMapping
issue: #98
1 parent 4c53a0c commit f7327c0

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = "."
22

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

77
include_ext = ["go"]
88
exclude_dir = ["dist"]

README.cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ interface Cmd {
6969
args: string[]; // 程序命令行参数
7070
env?: string[]; // 程序环境变量
7171

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

7676
// 资源限制

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ interface Cmd {
6969
args: string[]; // command line argument
7070
env?: string[]; // environment
7171

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

envexec/file_prepare.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ func prepareFds(r *Group, newStoreFile NewStoreFile) (f [][]*os.File, p [][]pipe
243243

244244
// prepare pipes
245245
for _, p := range r.Pipes {
246+
if files[p.Out.Index][p.Out.Fd] != nil {
247+
return nil, nil, fmt.Errorf("pipe mapping to existing file descriptor: out %d/%d", p.Out.Index, p.Out.Fd)
248+
}
249+
if files[p.In.Index][p.In.Fd] != nil {
250+
return nil, nil, fmt.Errorf("pipe mapping to existing file descriptor: in %d/%d", p.In.Index, p.In.Fd)
251+
}
246252
out, in, pc, err := pipe(p, newStoreFile)
247253
if err != nil {
248254
return nil, nil, err
@@ -254,6 +260,15 @@ func prepareFds(r *Group, newStoreFile NewStoreFile) (f [][]*os.File, p [][]pipe
254260
pipeToCollect[p.In.Index] = append(pipeToCollect[p.In.Index], *pc)
255261
}
256262
}
263+
264+
// null check
265+
for i, fds := range files {
266+
for j, f := range fds {
267+
if f == nil {
268+
return nil, nil, fmt.Errorf("null passed to files for index/fd: %d/%d", i, j)
269+
}
270+
}
271+
}
257272
return files, pipeToCollect, nil
258273
}
259274

0 commit comments

Comments
 (0)