aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-04-15 14:54:59 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-04-16 14:20:36 +0000
commit4cd91fc0b5007710bf0f38de6319ce24c31a52e5 (patch)
tree025210f316d065a63e680a054ab04c017ebc7315 /prog
parent7e9780e93983e03547322aab489429ae4a7d2fa3 (diff)
pkg/ipc: pass only exec encoding to Exec
Does not require passing text program to ipc.Env.Exec. Make it possible to provide just the exec encoding. This requires moving fallback coverage to the host since it need the program.
Diffstat (limited to 'prog')
-rw-r--r--prog/encodingexec.go10
-rw-r--r--prog/encodingexec_test.go4
2 files changed, 7 insertions, 7 deletions
diff --git a/prog/encodingexec.go b/prog/encodingexec.go
index 40cfc9592..fb8e5fbaf 100644
--- a/prog/encodingexec.go
+++ b/prog/encodingexec.go
@@ -23,7 +23,6 @@ package prog
import (
"encoding/binary"
- "errors"
"fmt"
"reflect"
"sort"
@@ -63,8 +62,6 @@ const (
execMaxCommands = 1000 // executor knows about this constant (kMaxCommands)
)
-var ErrExecBufferTooSmall = errors.New("encodingexec: provided buffer is too small")
-
// SerializeForExec serializes program p for execution by process pid into the provided buffer.
// Returns number of bytes written to the buffer.
// If the provided buffer is too small for the program an error is returned.
@@ -81,8 +78,11 @@ func (p *Prog) SerializeForExec() ([]byte, error) {
w.serializeCall(c)
}
w.write(execInstrEOF)
- if len(w.buf) > ExecBufferSize || w.copyoutSeq > execMaxCommands {
- return nil, ErrExecBufferTooSmall
+ if len(w.buf) > ExecBufferSize {
+ return nil, fmt.Errorf("encodingexec: too large program (%v/%v)", len(w.buf), ExecBufferSize)
+ }
+ if w.copyoutSeq > execMaxCommands {
+ return nil, fmt.Errorf("encodingexec: too many resources (%v/%v)", w.copyoutSeq, execMaxCommands)
}
return w.buf, nil
}
diff --git a/prog/encodingexec_test.go b/prog/encodingexec_test.go
index 357cca18b..5dfcbd0e3 100644
--- a/prog/encodingexec_test.go
+++ b/prog/encodingexec_test.go
@@ -752,8 +752,8 @@ func TestSerializeForExecOverflow(t *testing.T) {
t.Fatal(err)
}
_, err = p.SerializeForExec()
- if test.overflow && err != ErrExecBufferTooSmall {
- t.Fatalf("want overflow but got %v", err)
+ if test.overflow && err == nil {
+ t.Fatalf("want overflow but got no error")
}
if !test.overflow && err != nil {
t.Fatalf("want no overflow but got %v", err)