Skip to content

Commit

Permalink
fix(decl): use SetUint for open_mode uint32 field
Browse files Browse the repository at this point in the history
The issue can be reproduced with the following test:

```
tests:
  - rule: DirectoryTraversalMonitoredFileRead
    name: test2
    runner: HostRunner
    before: "echo Hi"
    steps:
      - type: syscall
        name: open
        syscall: open
        args:
          pathname: "/etc/../etc/../etc/shadow"
          flags: 0
          mode: 0644
    after: "echo Bye"
```

It was crashing with:

```
panic: reflect: call of reflect.Value.SetInt on uint32 Value
```

After this fix it runs successfully:
```
2024-11-10T23:22:23.483+0100	info	root	/Users/jose.calvo/repos/event-generator/cmd/declarative/run/run.go:221	Starting test execution...	{"testName": "test2", "testIndex": 0}
2024-11-10T23:22:23.494+0100	info	root.runner.test.script	/Users/jose.calvo/repos/event-generator/pkg/test/script/shell/shell.go:174	Script log line	{"runnerType": "HostRunner", "testName": "test2", "testIndex": 0, "type": "stdout", "line": "Hi"}
2024-11-10T23:22:23.504+0100	debug	root.runner.test	/Users/jose.calvo/repos/event-generator/pkg/test/test/test.go:142	Executed test step	{"runnerType": "HostRunner", "testName": "test2", "testIndex": 0, "stepName": "open", "stepIndex": 0}
2024-11-10T23:22:23.510+0100	debug	root.runner.test	/Users/jose.calvo/repos/event-generator/pkg/test/test/test.go:187	Executed test step cleanup	{"runnerType": "HostRunner", "testName": "test2", "testIndex": 0, "stepName": "open", "stepIndex": 0}
2024-11-10T23:22:23.511+0100	info	root.runner.test.script	/Users/jose.calvo/repos/event-generator/pkg/test/script/shell/shell.go:174	Script log line	{"runnerType": "HostRunner", "testName": "test2", "testIndex": 0, "type": "stdout", "line": "Bye"}
2024-11-10T23:22:23.514+0100	info	root	/Users/jose.calvo/repos/event-generator/cmd/declarative/run/run.go:249	Test execution completed	{"testName": "test2", "testIndex": 0}
```

Signed-off-by: José Antonio Calvo <[email protected]>
  • Loading branch information
jacalvo committed Nov 10, 2024
1 parent f431fbb commit 6981eb0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/test/step/syscall/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func setArgFieldValue(argField *field.Field, value string) error {
if err != nil {
return fmt.Errorf("cannot parse value as open mode: %w", err)
}
argFieldValue.SetInt(int64(openMode))
argFieldValue.SetUint(uint64(openMode))
case field.TypeOpenHow:
openHow, err := parseOpenHow(value)
if err != nil {
Expand Down

0 comments on commit 6981eb0

Please sign in to comment.