Skip to content

Commit ebd1345

Browse files
authored
Fix out of bounds error in strace.go (#348)
* strace.go: fix index out of bounds error and add nil checking for regex match Signed-off-by: Max Fisher <[email protected]> * strace_test.go: add missing comma Signed-off-by: Max Fisher <[email protected]> * strace_test.go: fix typo in test Signed-off-by: Max Fisher <[email protected]> * strace.go: make regex consistent with other ones Signed-off-by: Max Fisher <[email protected]> Signed-off-by: Max Fisher <[email protected]>
1 parent 3bf88c8 commit ebd1345

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

internal/strace/strace.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ var (
4040
unlinkPatten = regexp.MustCompile(`0x[a-f\d]+ ([^)]+)`)
4141

4242
// unlinkat(0x4 /tmp/pip-pip-egg-info-ng4_5gp_/temps.egg-info, 0x7fe0031c9a10 top_level.txt, 0x0)
43-
unlinkatPattern = regexp.MustCompile(`0x[a-f\d]+ ([^,]+), 0x[a-f\d]+ ([^,]+), 0x[a-f\d]+`)
43+
// unlinkat(AT_FDCWD /app, 0x5569a7e83380 /app/vendor/composer/e06632ca, 0x200)
44+
unlinkatPattern = regexp.MustCompile(`[^\s]+ ([^,]+), 0x[a-f\d]+ ([^,]+), 0x[a-f\d]+`)
4445
)
4546

4647
type FileInfo struct {
@@ -244,12 +245,18 @@ func (r *Result) parseSyscall(syscall, args string) error {
244245
r.recordFileAccess(path, true, false, false)
245246
case "unlink":
246247
match := unlinkPatten.FindStringSubmatch(args)
248+
if match == nil {
249+
return fmt.Errorf("Failed to parse unlink args: %s", args)
250+
}
247251
path := match[1]
248252
log.Debug("unlink",
249253
"path", path)
250254
r.recordFileAccess(path, false, false, true)
251255
case "unlinkat":
252256
match := unlinkatPattern.FindStringSubmatch(args)
257+
if match == nil {
258+
return fmt.Errorf("Failed to parse unlinkat args: %s", args)
259+
}
253260
path := joinPaths(match[1], match[2])
254261
log.Debug("unlinkat",
255262
"path", path)

internal/strace/strace_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ func TestParseFilesOneEntry(t *testing.T) {
202202
Delete: true,
203203
},
204204
},
205+
{
206+
name: "unlinkat_2",
207+
input: "I0907 23:56:32.113900 302 strace.go:631] [ 48: 48] rm X unlinkat(AT_FDCWD /app, 0x5569a7e83380 /app/vendor/composer/e06632ca, 0x200) = 0 (0x0) (69.951µs)",
208+
want: strace.FileInfo{
209+
Path: "/app/vendor/composer/e06632ca",
210+
Delete: true,
211+
},
212+
},
205213
}
206214
for _, test := range tests {
207215
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)