From 686e8c129cfafed4430334a2d6156d4cd9252767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 20 Oct 2024 21:14:24 +0100 Subject: [PATCH] interp: let HandlerContext.Stdin be nil again when there is no stdin We recently changed Runner.stdin from an io.Reader to an *os.File. One unintended consequence of this change is that HandlerContext.Stdin is filled directly from that value, so when the file was nil, we would now fill Stdin with a typed nil, which is not nil. This new behavior was unintentional and entirely confusing. Avoid it, and add a comment to ensure we don't fall into that again. --- interp/runner.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interp/runner.go b/interp/runner.go index 24597145..4ddfeb6b 100644 --- a/interp/runner.go +++ b/interp/runner.go @@ -241,10 +241,12 @@ func (r *Runner) handlerCtx(ctx context.Context) context.Context { hc := HandlerContext{ Env: &overlayEnviron{parent: r.writeEnv}, Dir: r.Dir, - Stdin: r.stdin, Stdout: r.stdout, Stderr: r.stderr, } + if r.stdin != nil { // do not leave hc.Stdin as a typed nil + hc.Stdin = r.stdin + } return context.WithValue(ctx, handlerCtxKey{}, hc) }