Skip to content

Commit 34eea86

Browse files
committed
syscall: enforce NULL termination of C string returned from getcwd
Fixes feedback on tinygo-org#4027.
1 parent cb87062 commit 34eea86

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/syscall/libc_wasip2.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,8 @@ func getcwd(buf *byte, size uint) *byte {
13491349
return nil
13501350
}
13511351

1352-
// TODO(dgryski): null termination?
1353-
copy(unsafe.Slice(buf, size), cwd)
1352+
s := unsafe.Slice(buf, size)
1353+
s[size-1] = 0 // Enforce NULL termination
1354+
copy(s, cwd)
13541355
return buf
13551356
}

0 commit comments

Comments
 (0)