aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-04-15 14:54:58 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-04-16 14:20:36 +0000
commitf8f619e676a9c568c10ac690b37f8b414cd0d52b (patch)
tree80b0b1f72e63158df06d9b83267f45555717e700 /pkg
parentea9bf35499d55e77ffac7d9939bb53949162dac6 (diff)
prog: don't require preallocated buffer for exec encoding
If we send exec encoding to the fuzzer, it's not necessary to serialize exec encoding into existing buffer (currnetly we serialize directly into shmem). So simplify code by serializing into a new slice.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/csource.go5
-rw-r--r--pkg/ipc/ipc.go11
2 files changed, 7 insertions, 9 deletions
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index 96237e64b..3d019a59c 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -239,12 +239,11 @@ func (ctx *context) generateSyscallDefines() string {
}
func (ctx *context) generateProgCalls(p *prog.Prog, trace bool) ([]string, []uint64, error) {
- exec := make([]byte, prog.ExecBufferSize)
- progSize, err := p.SerializeForExec(exec)
+ exec, err := p.SerializeForExec()
if err != nil {
return nil, nil, fmt.Errorf("failed to serialize program: %w", err)
}
- decoded, err := ctx.target.DeserializeExec(exec[:progSize], nil)
+ decoded, err := ctx.target.DeserializeExec(exec, nil)
if err != nil {
return nil, nil, err
}
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
index 536b494e7..ea2e22569 100644
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -185,7 +185,6 @@ func MakeEnv(config *Config, pid int) (*Env, error) {
}
}()
} else {
- inmem = make([]byte, prog.ExecBufferSize)
outmem = make([]byte, outputSize)
}
env := &Env{
@@ -254,15 +253,15 @@ func (env *Env) Close() error {
// hanged: program hanged and was killed
// err0: failed to start the process or bug in executor itself.
func (env *Env) Exec(opts *ExecOpts, p *prog.Prog) (output []byte, info *ProgInfo, hanged bool, err0 error) {
- // Copy-in serialized program.
- progSize, err := p.SerializeForExec(env.in)
+ progData, err := p.SerializeForExec()
if err != nil {
err0 = err
return
}
- var progData []byte
- if !env.config.UseShmem {
- progData = env.in[:progSize]
+ // Copy-in serialized program.
+ if env.config.UseShmem {
+ copy(env.in, progData)
+ progData = nil
}
// Zero out the first two words (ncmd and nsig), so that we don't have garbage there
// if executor crashes before writing non-garbage there.