Skip to content

Commit 68a4a8e

Browse files
tklausergopherbot
authored andcommitted
unix: avoid nil pointer dereference in Utime
Passing a nil buf *Utimbuf to Utime on linux/{arm,arm64,loong64,riscv64} will cause a nil pointer dereference. Check buf explicitly to avoid this case. Change-Id: Ifb719f83029002f043919daa066af6b1fb4ebe03 Reviewed-on: https://go-review.googlesource.com/c/sys/+/764562 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: David Chase <drchase@google.com>
1 parent 690c91f commit 68a4a8e

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

unix/syscall_linux_arm.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func Time(t *Time_t) (Time_t, error) {
8282
}
8383

8484
func Utime(path string, buf *Utimbuf) error {
85+
if buf == nil {
86+
return Utimes(path, nil)
87+
}
8588
tv := []Timeval{
8689
{Sec: buf.Actime},
8790
{Sec: buf.Modtime},

unix/syscall_linux_arm64.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func Time(t *Time_t) (Time_t, error) {
113113
}
114114

115115
func Utime(path string, buf *Utimbuf) error {
116+
if buf == nil {
117+
return Utimes(path, nil)
118+
}
116119
tv := []Timeval{
117120
{Sec: buf.Actime},
118121
{Sec: buf.Modtime},

unix/syscall_linux_loong64.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ func Time(t *Time_t) (Time_t, error) {
150150
}
151151

152152
func Utime(path string, buf *Utimbuf) error {
153+
if buf == nil {
154+
return Utimes(path, nil)
155+
}
153156
tv := []Timeval{
154157
{Sec: buf.Actime},
155158
{Sec: buf.Modtime},

unix/syscall_linux_riscv64.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func Time(t *Time_t) (Time_t, error) {
112112
}
113113

114114
func Utime(path string, buf *Utimbuf) error {
115+
if buf == nil {
116+
return Utimes(path, nil)
117+
}
115118
tv := []Timeval{
116119
{Sec: buf.Actime},
117120
{Sec: buf.Modtime},

0 commit comments

Comments
 (0)