Skip to content

Commit 4d8c7ae

Browse files
zkoopmansshentubot
authored andcommitted
Fixing O_TRUNC behavior to match Linux.
PiperOrigin-RevId: 224351139 Change-Id: I9453bd75e5a8d38db406bb47fdc01038ac60922e
1 parent 7f35dad commit 4d8c7ae

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

pkg/sentry/syscalls/linux/flags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
// flagsToPermissions returns a Permissions object from Linux flags.
2323
// This includes truncate permission if O_TRUNC is set in the mask.
2424
func flagsToPermissions(mask uint) (p fs.PermMask) {
25+
if mask&linux.O_TRUNC != 0 {
26+
p.Write = true
27+
}
2528
switch mask & linux.O_ACCMODE {
2629
case linux.O_WRONLY:
2730
p.Write = true

pkg/sentry/syscalls/linux/sys_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func openAt(t *kernel.Task, dirFD kdefs.FD, addr usermem.Addr, flags uint) (fd u
170170
if dirPath {
171171
return syserror.ENOTDIR
172172
}
173-
if fileFlags.Write && flags&linux.O_TRUNC != 0 {
173+
if flags&linux.O_TRUNC != 0 {
174174
if err := d.Inode.Truncate(t, d, 0); err != nil {
175175
return err
176176
}

0 commit comments

Comments
 (0)