From ed9bcdca2162bd7825915be3675fdc3a2c52c1af Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 12:33:47 +0200 Subject: [PATCH 01/13] integer-overflow - initial implementation --- inotify.go | 26 +++++++++++++++++++++++++- inotify_test.go | 18 +++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/inotify.go b/inotify.go index 7710151..7ebc34e 100644 --- a/inotify.go +++ b/inotify.go @@ -16,8 +16,10 @@ import ( // max number of events to read at once const maxEvents = 1024 +const maxUint32 = int(^uint32(0)) var TimeoutError = errors.New("Inotify timeout") +var UnsignedIntegerOverflowError = errors.New("unsigned integer overflow") type addWatchRequest struct { pathName string @@ -107,11 +109,15 @@ func NewInotify(ctx context.Context) (*Inotify, error) { return case req := <-inotify.addWatchIn: wd, err := syscall.InotifyAddWatch(fd, req.pathName, req.mask) - if err == nil { + verr := ValidateInteger(wd) + if err == nil && verr != nil { wdu32 := uint32(wd) watches[req.pathName] = wdu32 paths[wdu32] = req.pathName } + if err == nil && verr != nil { + err = verr + } select { case req.result <- err: case <-ctx.Done(): @@ -178,6 +184,17 @@ func NewInotify(ctx context.Context) (*Inotify, error) { offset := 0 for offset+syscall.SizeofInotifyEvent <= n { event := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset])) + verr := ValidateInteger(int(event.Wd)) + if verr != nil { + response.err = UnsignedIntegerOverflowError + response.events = events + select { + case req.result <- response: + case <-ctx.Done(): + } + continue main + } + var name string { nameStart := offset + syscall.SizeofInotifyEvent @@ -325,3 +342,10 @@ func (i *Inotify) ReadDeadline(deadline time.Time) ([]InotifyEvent, error) { } } } + +func ValidateInteger(wd int) error { + if wd > 0 && wd > maxUint32 { + return UnsignedIntegerOverflowError + } + return nil +} diff --git a/inotify_test.go b/inotify_test.go index 736a834..4d00d7c 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -2,6 +2,7 @@ package gonotify import ( "context" + "errors" "fmt" "io/ioutil" "os" @@ -75,7 +76,6 @@ func BenchmarkWatch(b *testing.B) { } func TestInotify(t *testing.T) { - ctx := context.Background() dir, err := ioutil.TempDir("", "TestInotify") @@ -332,3 +332,19 @@ func TestInotify(t *testing.T) { }) } + +func TestValidateInteger(t *testing.T) { + t.Run("Overflows", func(t *testing.T) { + verr := ValidateInteger(5294967295) + if !errors.Is(verr, UnsignedIntegerOverflowError) { + t.Error(verr) + } + }) + + t.Run("Ok", func(t *testing.T) { + verr := ValidateInteger(22949) + if errors.Is(verr, UnsignedIntegerOverflowError) { + t.Error(verr) + } + }) +} From 88989b2ecc6c231e60a5f818992f40026e038157 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 18:33:12 +0200 Subject: [PATCH 02/13] integer-overflow - naming and exports --- inotify.go | 24 ++++++++++++------------ inotify_test.go | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/inotify.go b/inotify.go index 7ebc34e..dbf96bb 100644 --- a/inotify.go +++ b/inotify.go @@ -16,10 +16,12 @@ import ( // max number of events to read at once const maxEvents = 1024 -const maxUint32 = int(^uint32(0)) + +// maximum size of unsigned int32 +const MaxUint32 = int(^uint32(0)) var TimeoutError = errors.New("Inotify timeout") -var UnsignedIntegerOverflowError = errors.New("unsigned integer overflow") +var WatchesNumberUint32OverflowError = errors.New("watches number overflow") type addWatchRequest struct { pathName string @@ -109,17 +111,15 @@ func NewInotify(ctx context.Context) (*Inotify, error) { return case req := <-inotify.addWatchIn: wd, err := syscall.InotifyAddWatch(fd, req.pathName, req.mask) - verr := ValidateInteger(wd) - if err == nil && verr != nil { + verr := ValidateVsMaximumAllowedUint32Size(wd) + if err == nil && verr == nil { wdu32 := uint32(wd) watches[req.pathName] = wdu32 paths[wdu32] = req.pathName } - if err == nil && verr != nil { - err = verr - } select { case req.result <- err: + case req.result <- verr: case <-ctx.Done(): } case req := <-inotify.readIn: @@ -184,9 +184,9 @@ func NewInotify(ctx context.Context) (*Inotify, error) { offset := 0 for offset+syscall.SizeofInotifyEvent <= n { event := (*syscall.InotifyEvent)(unsafe.Pointer(&buf[offset])) - verr := ValidateInteger(int(event.Wd)) + verr := ValidateVsMaximumAllowedUint32Size(int(event.Wd)) if verr != nil { - response.err = UnsignedIntegerOverflowError + response.err = WatchesNumberUint32OverflowError response.events = events select { case req.result <- response: @@ -343,9 +343,9 @@ func (i *Inotify) ReadDeadline(deadline time.Time) ([]InotifyEvent, error) { } } -func ValidateInteger(wd int) error { - if wd > 0 && wd > maxUint32 { - return UnsignedIntegerOverflowError +func ValidateVsMaximumAllowedUint32Size(wd int) error { + if wd > 0 && wd > MaxUint32 { + return WatchesNumberUint32OverflowError } return nil } diff --git a/inotify_test.go b/inotify_test.go index 4d00d7c..d518dc7 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -335,14 +335,14 @@ func TestInotify(t *testing.T) { func TestValidateInteger(t *testing.T) { t.Run("Overflows", func(t *testing.T) { - verr := ValidateInteger(5294967295) + verr := ValidateVsMaximumAllowedUint32Size(5294967295) if !errors.Is(verr, UnsignedIntegerOverflowError) { t.Error(verr) } }) t.Run("Ok", func(t *testing.T) { - verr := ValidateInteger(22949) + verr := ValidateVsMaximumAllowedUint32Size(22949) if errors.Is(verr, UnsignedIntegerOverflowError) { t.Error(verr) } From 9514d978b67747d0981870ad3a6a272d5166afa7 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 18:41:39 +0200 Subject: [PATCH 03/13] integer-overflow - test fix --- inotify_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inotify_test.go b/inotify_test.go index b8fc246..f83db36 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -335,14 +335,14 @@ func TestInotify(t *testing.T) { func TestValidateInteger(t *testing.T) { t.Run("Overflows", func(t *testing.T) { verr := ValidateVsMaximumAllowedUint32Size(5294967295) - if !errors.Is(verr, UnsignedIntegerOverflowError) { + if !errors.Is(verr, WatchesNumberUint32OverflowError) { t.Error(verr) } }) t.Run("Ok", func(t *testing.T) { verr := ValidateVsMaximumAllowedUint32Size(22949) - if errors.Is(verr, UnsignedIntegerOverflowError) { + if errors.Is(verr, WatchesNumberUint32OverflowError) { t.Error(verr) } }) From 79a1dcf6ca9129efd0cd0a418f626733b98dbb51 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 18:44:49 +0200 Subject: [PATCH 04/13] integer-overflow - reduce number of changes --- inotify.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inotify.go b/inotify.go index 564c930..6a5d74d 100644 --- a/inotify.go +++ b/inotify.go @@ -16,7 +16,7 @@ import ( ) const ( - // max number of events to read at once + // maxEvents is the maximum number of events to read in one syscall maxEvents = 1024 // maximum size of unsigned int32 From d7116114f3a0db8dfccd21df2fc8645d3343e309 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 18:46:15 +0200 Subject: [PATCH 05/13] integer-overflow - validation conditions update --- inotify.go | 2 +- inotify_test.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/inotify.go b/inotify.go index 6a5d74d..55ad01f 100644 --- a/inotify.go +++ b/inotify.go @@ -461,7 +461,7 @@ func (i *Inotify) ReadDeadline(deadline time.Time) ([]InotifyEvent, error) { } func ValidateVsMaximumAllowedUint32Size(wd int) error { - if wd > 0 && wd > MaxUint32 { + if wd < 0 || wd > MaxUint32 { return WatchesNumberUint32OverflowError } return nil diff --git a/inotify_test.go b/inotify_test.go index f83db36..49eca27 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -340,6 +340,13 @@ func TestValidateInteger(t *testing.T) { } }) + t.Run("Negative", func(t *testing.T) { + verr := ValidateVsMaximumAllowedUint32Size(-1) + if !errors.Is(verr, WatchesNumberUint32OverflowError) { + t.Error(verr) + } + }) + t.Run("Ok", func(t *testing.T) { verr := ValidateVsMaximumAllowedUint32Size(22949) if errors.Is(verr, WatchesNumberUint32OverflowError) { From 5a393f6ef81ae51ea719af03a7bb43348defa0c5 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Sat, 5 Oct 2024 18:59:57 +0200 Subject: [PATCH 06/13] integer-overflow - hint --- inotify.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inotify.go b/inotify.go index 55ad01f..1067450 100644 --- a/inotify.go +++ b/inotify.go @@ -161,6 +161,12 @@ func NewInotify(ctx context.Context) (*Inotify, error) { offset = nameEnd } + // how to address? + // verr := ValidateVsMaximumAllowedUint32Size(int(event.Wd)) + // if verr != nil { + // return nil, verr + // } + req := getPathRequest{wd: uint32(event.Wd), result: make(chan string)} var watchName string From da65ebceafb524a0d4be656b050781a222921a12 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 17:54:39 +0200 Subject: [PATCH 07/13] integer-overflow - custom syscall with replacement to int instead of uint32 --- event.go | 2 +- inotify.go | 45 +++++++++-------------------- inotify_test.go | 24 --------------- syscallf/syscall_linux.go | 31 ++++++++++++++++++++ syscallf/zsyscall_linux_386.go | 17 +++++++++++ syscallf/zsyscall_linux_amd64.go | 17 +++++++++++ syscallf/zsyscall_linux_arm.go | 17 +++++++++++ syscallf/zsyscall_linux_arm64.go | 17 +++++++++++ syscallf/zsyscall_linux_loong64.go | 17 +++++++++++ syscallf/zsyscall_linux_mips.go | 17 +++++++++++ syscallf/zsyscall_linux_mips64.go | 17 +++++++++++ syscallf/zsyscall_linux_mips64le.go | 17 +++++++++++ syscallf/zsyscall_linux_mipsle.go | 17 +++++++++++ syscallf/zsyscall_linux_ppc64.go | 17 +++++++++++ syscallf/zsyscall_linux_ppc64le.go | 17 +++++++++++ syscallf/zsyscall_linux_riscv64.go | 17 +++++++++++ syscallf/zsyscall_linux_s390x.go | 17 +++++++++++ 17 files changed, 267 insertions(+), 56 deletions(-) create mode 100644 syscallf/syscall_linux.go create mode 100644 syscallf/zsyscall_linux_386.go create mode 100644 syscallf/zsyscall_linux_amd64.go create mode 100644 syscallf/zsyscall_linux_arm.go create mode 100644 syscallf/zsyscall_linux_arm64.go create mode 100644 syscallf/zsyscall_linux_loong64.go create mode 100644 syscallf/zsyscall_linux_mips.go create mode 100644 syscallf/zsyscall_linux_mips64.go create mode 100644 syscallf/zsyscall_linux_mips64le.go create mode 100644 syscallf/zsyscall_linux_mipsle.go create mode 100644 syscallf/zsyscall_linux_ppc64.go create mode 100644 syscallf/zsyscall_linux_ppc64le.go create mode 100644 syscallf/zsyscall_linux_riscv64.go create mode 100644 syscallf/zsyscall_linux_s390x.go diff --git a/event.go b/event.go index 45bf64d..e1caef0 100644 --- a/event.go +++ b/event.go @@ -81,7 +81,7 @@ func InMaskToString(in_mask uint32) string { // InotifyEvent is the go representation of inotify_event found in sys/inotify.h type InotifyEvent struct { // Watch descriptor - Wd uint32 + Wd int // File or directory name Name string // Contains bits that describe the event that occurred diff --git a/inotify.go b/inotify.go index 1067450..930ed8d 100644 --- a/inotify.go +++ b/inotify.go @@ -13,14 +13,13 @@ import ( "syscall" "time" "unsafe" + + "github.com/illarion/gonotify/v2/syscallf" ) const ( // maxEvents is the maximum number of events to read in one syscall maxEvents = 1024 - - // maximum size of unsigned int32 - MaxUint32 = int(^uint32(0)) ) var TimeoutError = errors.New("Inotify timeout") @@ -42,7 +41,7 @@ type Inotify struct { ctx context.Context done chan struct{} addWatchIn chan addWatchRequest - rmByWdIn chan uint32 + rmByWdIn chan int rmByPathIn chan string eventsOut chan eventItem @@ -64,13 +63,13 @@ func NewInotify(ctx context.Context) (*Inotify, error) { ctx: ctx, done: make(chan struct{}), addWatchIn: make(chan addWatchRequest), - rmByWdIn: make(chan uint32), + rmByWdIn: make(chan int), rmByPathIn: make(chan string), eventsOut: make(chan eventItem, maxEvents), } type getPathRequest struct { - wd uint32 + wd int result chan string } @@ -161,13 +160,7 @@ func NewInotify(ctx context.Context) (*Inotify, error) { offset = nameEnd } - // how to address? - // verr := ValidateVsMaximumAllowedUint32Size(int(event.Wd)) - // if verr != nil { - // return nil, verr - // } - - req := getPathRequest{wd: uint32(event.Wd), result: make(chan string)} + req := getPathRequest{wd: int(event.Wd), result: make(chan string)} var watchName string select { @@ -190,7 +183,7 @@ func NewInotify(ctx context.Context) (*Inotify, error) { name = filepath.Join(watchName, name) inotifyEvent := InotifyEvent{ - Wd: uint32(event.Wd), + Wd: int(event.Wd), Name: name, Mask: event.Mask, Cookie: event.Cookie, @@ -233,8 +226,8 @@ func NewInotify(ctx context.Context) (*Inotify, error) { //defer cancel() defer wg.Done() - watches := make(map[string]uint32) - paths := make(map[uint32]string) + watches := make(map[string]int) + paths := make(map[int]string) for { select { @@ -262,7 +255,7 @@ func NewInotify(ctx context.Context) (*Inotify, error) { } for _, w := range watches { - _, err := syscall.InotifyRmWatch(fd, w) + _, err := syscallf.InotifyRmWatch(fd, w) if err != nil { continue } @@ -271,15 +264,12 @@ func NewInotify(ctx context.Context) (*Inotify, error) { return case req := <-inotify.addWatchIn: wd, err := syscall.InotifyAddWatch(fd, req.pathName, req.mask) - verr := ValidateVsMaximumAllowedUint32Size(wd) - if err == nil && verr == nil { - wdu32 := uint32(wd) - watches[req.pathName] = wdu32 - paths[wdu32] = req.pathName + if err == nil { + watches[req.pathName] = wd + paths[wd] = req.pathName } select { case req.result <- err: - case req.result <- verr: case <-ctx.Done(): } case wd := <-inotify.rmByWdIn: @@ -344,7 +334,7 @@ func (i *Inotify) AddWatch(pathName string, mask uint32) error { } // RmWd removes watch by watch descriptor -func (i *Inotify) RmWd(wd uint32) error { +func (i *Inotify) RmWd(wd int) error { select { case <-i.ctx.Done(): return i.ctx.Err() @@ -465,10 +455,3 @@ func (i *Inotify) ReadDeadline(deadline time.Time) ([]InotifyEvent, error) { } } - -func ValidateVsMaximumAllowedUint32Size(wd int) error { - if wd < 0 || wd > MaxUint32 { - return WatchesNumberUint32OverflowError - } - return nil -} diff --git a/inotify_test.go b/inotify_test.go index 49eca27..bb2a34c 100644 --- a/inotify_test.go +++ b/inotify_test.go @@ -2,7 +2,6 @@ package gonotify import ( "context" - "errors" "fmt" "io/ioutil" "os" @@ -331,26 +330,3 @@ func TestInotify(t *testing.T) { }) } - -func TestValidateInteger(t *testing.T) { - t.Run("Overflows", func(t *testing.T) { - verr := ValidateVsMaximumAllowedUint32Size(5294967295) - if !errors.Is(verr, WatchesNumberUint32OverflowError) { - t.Error(verr) - } - }) - - t.Run("Negative", func(t *testing.T) { - verr := ValidateVsMaximumAllowedUint32Size(-1) - if !errors.Is(verr, WatchesNumberUint32OverflowError) { - t.Error(verr) - } - }) - - t.Run("Ok", func(t *testing.T) { - verr := ValidateVsMaximumAllowedUint32Size(22949) - if errors.Is(verr, WatchesNumberUint32OverflowError) { - t.Error(verr) - } - }) -} diff --git a/syscallf/syscall_linux.go b/syscallf/syscall_linux.go new file mode 100644 index 0000000..3d71ae1 --- /dev/null +++ b/syscallf/syscall_linux.go @@ -0,0 +1,31 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package syscallf + +import "syscall" + +// Do the interface allocations only once for common +// Errno values. +var ( + errEAGAIN error = syscall.EAGAIN + errEINVAL error = syscall.EINVAL + errENOENT error = syscall.ENOENT +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case syscall.EAGAIN: + return errEAGAIN + case syscall.EINVAL: + return errEINVAL + case syscall.ENOENT: + return errENOENT + } + return e +} diff --git a/syscallf/zsyscall_linux_386.go b/syscallf/zsyscall_linux_386.go new file mode 100644 index 0000000..4733e90 --- /dev/null +++ b/syscallf/zsyscall_linux_386.go @@ -0,0 +1,17 @@ +// mksyscall.pl -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && 386 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_amd64.go b/syscallf/zsyscall_linux_amd64.go new file mode 100644 index 0000000..80856cf --- /dev/null +++ b/syscallf/zsyscall_linux_amd64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && amd64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_arm.go b/syscallf/zsyscall_linux_arm.go new file mode 100644 index 0000000..bca86a0 --- /dev/null +++ b/syscallf/zsyscall_linux_arm.go @@ -0,0 +1,17 @@ +// mksyscall.pl -l32 -arm -tags linux,arm syscall_linux.go syscall_linux_arm.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && arm + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_arm64.go b/syscallf/zsyscall_linux_arm64.go new file mode 100644 index 0000000..d579422 --- /dev/null +++ b/syscallf/zsyscall_linux_arm64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,arm64 syscall_linux.go syscall_linux_arm64.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && arm64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_loong64.go b/syscallf/zsyscall_linux_loong64.go new file mode 100644 index 0000000..1ffe990 --- /dev/null +++ b/syscallf/zsyscall_linux_loong64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,loong64 syscall_linux.go syscall_linux_loong64.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && loong64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_mips.go b/syscallf/zsyscall_linux_mips.go new file mode 100644 index 0000000..37b8003 --- /dev/null +++ b/syscallf/zsyscall_linux_mips.go @@ -0,0 +1,17 @@ +// mksyscall.pl -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && mips + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_mips64.go b/syscallf/zsyscall_linux_mips64.go new file mode 100644 index 0000000..a85aa46 --- /dev/null +++ b/syscallf/zsyscall_linux_mips64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && mips64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_mips64le.go b/syscallf/zsyscall_linux_mips64le.go new file mode 100644 index 0000000..cf4b235 --- /dev/null +++ b/syscallf/zsyscall_linux_mips64le.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,mips64le syscall_linux.go syscall_linux_mips64x.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && mips64le + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_mipsle.go b/syscallf/zsyscall_linux_mipsle.go new file mode 100644 index 0000000..8ed7d6d --- /dev/null +++ b/syscallf/zsyscall_linux_mipsle.go @@ -0,0 +1,17 @@ +// mksyscall.pl -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && mipsle + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_ppc64.go b/syscallf/zsyscall_linux_ppc64.go new file mode 100644 index 0000000..5c81140 --- /dev/null +++ b/syscallf/zsyscall_linux_ppc64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && ppc64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_ppc64le.go b/syscallf/zsyscall_linux_ppc64le.go new file mode 100644 index 0000000..cba41de --- /dev/null +++ b/syscallf/zsyscall_linux_ppc64le.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && ppc64le + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_riscv64.go b/syscallf/zsyscall_linux_riscv64.go new file mode 100644 index 0000000..2d18819 --- /dev/null +++ b/syscallf/zsyscall_linux_riscv64.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,riscv64 syscall_linux.go syscall_linux_riscv64.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && riscv64 + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/syscallf/zsyscall_linux_s390x.go b/syscallf/zsyscall_linux_s390x.go new file mode 100644 index 0000000..e9bbd23 --- /dev/null +++ b/syscallf/zsyscall_linux_s390x.go @@ -0,0 +1,17 @@ +// mksyscall.pl -tags linux,s390x syscall_linux.go syscall_linux_s390x.go +// Code generated by the command above; DO NOT EDIT. + +//go:build linux && s390x + +package syscallf + +import "syscall" + +func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} From b134174a7b271a8e3e83b59d182ab674fd0ff61f Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 17:56:50 +0200 Subject: [PATCH 08/13] integer-overflow - remove unused --- inotify.go | 1 - 1 file changed, 1 deletion(-) diff --git a/inotify.go b/inotify.go index 930ed8d..3771666 100644 --- a/inotify.go +++ b/inotify.go @@ -23,7 +23,6 @@ const ( ) var TimeoutError = errors.New("Inotify timeout") -var WatchesNumberUint32OverflowError = errors.New("watches number overflow") type addWatchRequest struct { pathName string From 7f832286b6f1d48d290e7862b96a38f7a10386db Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 18:17:02 +0200 Subject: [PATCH 09/13] integer-overflow - copyright --- syscallf/syscall_linux.go | 5 ++--- syscallf/zsyscall_linux_386.go | 4 ++-- syscallf/zsyscall_linux_amd64.go | 4 ++-- syscallf/zsyscall_linux_arm.go | 4 ++-- syscallf/zsyscall_linux_arm64.go | 4 ++-- syscallf/zsyscall_linux_loong64.go | 4 ++-- syscallf/zsyscall_linux_mips.go | 4 ++-- syscallf/zsyscall_linux_mips64.go | 4 ++-- syscallf/zsyscall_linux_mips64le.go | 4 ++-- syscallf/zsyscall_linux_mipsle.go | 4 ++-- syscallf/zsyscall_linux_ppc64.go | 4 ++-- syscallf/zsyscall_linux_ppc64le.go | 4 ++-- syscallf/zsyscall_linux_riscv64.go | 4 ++-- syscallf/zsyscall_linux_s390x.go | 4 ++-- 14 files changed, 28 insertions(+), 29 deletions(-) diff --git a/syscallf/syscall_linux.go b/syscallf/syscall_linux.go index 3d71ae1..84396a4 100644 --- a/syscallf/syscall_linux.go +++ b/syscallf/syscall_linux.go @@ -1,6 +1,5 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch package syscallf diff --git a/syscallf/zsyscall_linux_386.go b/syscallf/zsyscall_linux_386.go index 4733e90..ad86c56 100644 --- a/syscallf/zsyscall_linux_386.go +++ b/syscallf/zsyscall_linux_386.go @@ -1,5 +1,5 @@ -// mksyscall.pl -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && 386 diff --git a/syscallf/zsyscall_linux_amd64.go b/syscallf/zsyscall_linux_amd64.go index 80856cf..84183b2 100644 --- a/syscallf/zsyscall_linux_amd64.go +++ b/syscallf/zsyscall_linux_amd64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && amd64 diff --git a/syscallf/zsyscall_linux_arm.go b/syscallf/zsyscall_linux_arm.go index bca86a0..52cb605 100644 --- a/syscallf/zsyscall_linux_arm.go +++ b/syscallf/zsyscall_linux_arm.go @@ -1,5 +1,5 @@ -// mksyscall.pl -l32 -arm -tags linux,arm syscall_linux.go syscall_linux_arm.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && arm diff --git a/syscallf/zsyscall_linux_arm64.go b/syscallf/zsyscall_linux_arm64.go index d579422..6c5c92d 100644 --- a/syscallf/zsyscall_linux_arm64.go +++ b/syscallf/zsyscall_linux_arm64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,arm64 syscall_linux.go syscall_linux_arm64.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && arm64 diff --git a/syscallf/zsyscall_linux_loong64.go b/syscallf/zsyscall_linux_loong64.go index 1ffe990..2ece2f5 100644 --- a/syscallf/zsyscall_linux_loong64.go +++ b/syscallf/zsyscall_linux_loong64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,loong64 syscall_linux.go syscall_linux_loong64.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && loong64 diff --git a/syscallf/zsyscall_linux_mips.go b/syscallf/zsyscall_linux_mips.go index 37b8003..581e135 100644 --- a/syscallf/zsyscall_linux_mips.go +++ b/syscallf/zsyscall_linux_mips.go @@ -1,5 +1,5 @@ -// mksyscall.pl -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && mips diff --git a/syscallf/zsyscall_linux_mips64.go b/syscallf/zsyscall_linux_mips64.go index a85aa46..61efe89 100644 --- a/syscallf/zsyscall_linux_mips64.go +++ b/syscallf/zsyscall_linux_mips64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && mips64 diff --git a/syscallf/zsyscall_linux_mips64le.go b/syscallf/zsyscall_linux_mips64le.go index cf4b235..69c4a54 100644 --- a/syscallf/zsyscall_linux_mips64le.go +++ b/syscallf/zsyscall_linux_mips64le.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,mips64le syscall_linux.go syscall_linux_mips64x.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && mips64le diff --git a/syscallf/zsyscall_linux_mipsle.go b/syscallf/zsyscall_linux_mipsle.go index 8ed7d6d..4b9ed0a 100644 --- a/syscallf/zsyscall_linux_mipsle.go +++ b/syscallf/zsyscall_linux_mipsle.go @@ -1,5 +1,5 @@ -// mksyscall.pl -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && mipsle diff --git a/syscallf/zsyscall_linux_ppc64.go b/syscallf/zsyscall_linux_ppc64.go index 5c81140..743f24a 100644 --- a/syscallf/zsyscall_linux_ppc64.go +++ b/syscallf/zsyscall_linux_ppc64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && ppc64 diff --git a/syscallf/zsyscall_linux_ppc64le.go b/syscallf/zsyscall_linux_ppc64le.go index cba41de..ba8f470 100644 --- a/syscallf/zsyscall_linux_ppc64le.go +++ b/syscallf/zsyscall_linux_ppc64le.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && ppc64le diff --git a/syscallf/zsyscall_linux_riscv64.go b/syscallf/zsyscall_linux_riscv64.go index 2d18819..6c7bc4b 100644 --- a/syscallf/zsyscall_linux_riscv64.go +++ b/syscallf/zsyscall_linux_riscv64.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,riscv64 syscall_linux.go syscall_linux_riscv64.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && riscv64 diff --git a/syscallf/zsyscall_linux_s390x.go b/syscallf/zsyscall_linux_s390x.go index e9bbd23..6e8e60e 100644 --- a/syscallf/zsyscall_linux_s390x.go +++ b/syscallf/zsyscall_linux_s390x.go @@ -1,5 +1,5 @@ -// mksyscall.pl -tags linux,s390x syscall_linux.go syscall_linux_s390x.go -// Code generated by the command above; DO NOT EDIT. +// Copyright 2009 The Go Authors. +// based on golang's syscall.InotifyRmWatch //go:build linux && s390x From f232993b766699c8d68489cb4aa78639345a1806 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 18:18:01 +0200 Subject: [PATCH 10/13] integer-overflow - more copyright --- syscallf/syscall_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syscallf/syscall_linux.go b/syscallf/syscall_linux.go index 84396a4..2d3dd68 100644 --- a/syscallf/syscall_linux.go +++ b/syscallf/syscall_linux.go @@ -1,5 +1,5 @@ // Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch +// based on golang's syscall_linux.go package syscallf From b7f99d1fdd2f798de06890431b94b48719fb5f35 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 18:24:51 +0200 Subject: [PATCH 11/13] integer-overflow - dry up --- syscallf/{syscall_linux.go => rm_watch.go} | 15 ++++++++++++--- syscallf/zsyscall_linux_386.go | 17 ----------------- syscallf/zsyscall_linux_amd64.go | 17 ----------------- syscallf/zsyscall_linux_arm.go | 17 ----------------- syscallf/zsyscall_linux_arm64.go | 17 ----------------- syscallf/zsyscall_linux_loong64.go | 17 ----------------- syscallf/zsyscall_linux_mips.go | 17 ----------------- syscallf/zsyscall_linux_mips64.go | 17 ----------------- syscallf/zsyscall_linux_mips64le.go | 17 ----------------- syscallf/zsyscall_linux_mipsle.go | 17 ----------------- syscallf/zsyscall_linux_ppc64.go | 17 ----------------- syscallf/zsyscall_linux_ppc64le.go | 17 ----------------- syscallf/zsyscall_linux_riscv64.go | 17 ----------------- syscallf/zsyscall_linux_s390x.go | 17 ----------------- 14 files changed, 12 insertions(+), 224 deletions(-) rename syscallf/{syscall_linux.go => rm_watch.go} (65%) delete mode 100644 syscallf/zsyscall_linux_386.go delete mode 100644 syscallf/zsyscall_linux_amd64.go delete mode 100644 syscallf/zsyscall_linux_arm.go delete mode 100644 syscallf/zsyscall_linux_arm64.go delete mode 100644 syscallf/zsyscall_linux_loong64.go delete mode 100644 syscallf/zsyscall_linux_mips.go delete mode 100644 syscallf/zsyscall_linux_mips64.go delete mode 100644 syscallf/zsyscall_linux_mips64le.go delete mode 100644 syscallf/zsyscall_linux_mipsle.go delete mode 100644 syscallf/zsyscall_linux_ppc64.go delete mode 100644 syscallf/zsyscall_linux_ppc64le.go delete mode 100644 syscallf/zsyscall_linux_riscv64.go delete mode 100644 syscallf/zsyscall_linux_s390x.go diff --git a/syscallf/syscall_linux.go b/syscallf/rm_watch.go similarity index 65% rename from syscallf/syscall_linux.go rename to syscallf/rm_watch.go index 2d3dd68..0fb5002 100644 --- a/syscallf/syscall_linux.go +++ b/syscallf/rm_watch.go @@ -1,6 +1,3 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall_linux.go - package syscallf import "syscall" @@ -28,3 +25,15 @@ func errnoErr(e syscall.Errno) error { } return e } + +func InotifyRmWatch(fd int, watchdesc int) (int, error) { + var success int + var err error + + r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) + success = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return success, err +} diff --git a/syscallf/zsyscall_linux_386.go b/syscallf/zsyscall_linux_386.go deleted file mode 100644 index ad86c56..0000000 --- a/syscallf/zsyscall_linux_386.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && 386 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_amd64.go b/syscallf/zsyscall_linux_amd64.go deleted file mode 100644 index 84183b2..0000000 --- a/syscallf/zsyscall_linux_amd64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && amd64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_arm.go b/syscallf/zsyscall_linux_arm.go deleted file mode 100644 index 52cb605..0000000 --- a/syscallf/zsyscall_linux_arm.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && arm - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_arm64.go b/syscallf/zsyscall_linux_arm64.go deleted file mode 100644 index 6c5c92d..0000000 --- a/syscallf/zsyscall_linux_arm64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && arm64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_loong64.go b/syscallf/zsyscall_linux_loong64.go deleted file mode 100644 index 2ece2f5..0000000 --- a/syscallf/zsyscall_linux_loong64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && loong64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_mips.go b/syscallf/zsyscall_linux_mips.go deleted file mode 100644 index 581e135..0000000 --- a/syscallf/zsyscall_linux_mips.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && mips - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_mips64.go b/syscallf/zsyscall_linux_mips64.go deleted file mode 100644 index 61efe89..0000000 --- a/syscallf/zsyscall_linux_mips64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && mips64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_mips64le.go b/syscallf/zsyscall_linux_mips64le.go deleted file mode 100644 index 69c4a54..0000000 --- a/syscallf/zsyscall_linux_mips64le.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && mips64le - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_mipsle.go b/syscallf/zsyscall_linux_mipsle.go deleted file mode 100644 index 4b9ed0a..0000000 --- a/syscallf/zsyscall_linux_mipsle.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && mipsle - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_ppc64.go b/syscallf/zsyscall_linux_ppc64.go deleted file mode 100644 index 743f24a..0000000 --- a/syscallf/zsyscall_linux_ppc64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && ppc64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_ppc64le.go b/syscallf/zsyscall_linux_ppc64le.go deleted file mode 100644 index ba8f470..0000000 --- a/syscallf/zsyscall_linux_ppc64le.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && ppc64le - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_riscv64.go b/syscallf/zsyscall_linux_riscv64.go deleted file mode 100644 index 6c7bc4b..0000000 --- a/syscallf/zsyscall_linux_riscv64.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && riscv64 - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} diff --git a/syscallf/zsyscall_linux_s390x.go b/syscallf/zsyscall_linux_s390x.go deleted file mode 100644 index 6e8e60e..0000000 --- a/syscallf/zsyscall_linux_s390x.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2009 The Go Authors. -// based on golang's syscall.InotifyRmWatch - -//go:build linux && s390x - -package syscallf - -import "syscall" - -func InotifyRmWatch(fd int, watchdesc int) (success int, err error) { - r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) - success = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} From 7ee073427bd735ab500c1b24b480a90d2999d427 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 18:25:22 +0200 Subject: [PATCH 12/13] integer-overflow - build flag --- syscallf/rm_watch.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syscallf/rm_watch.go b/syscallf/rm_watch.go index 0fb5002..d7f5152 100644 --- a/syscallf/rm_watch.go +++ b/syscallf/rm_watch.go @@ -1,3 +1,5 @@ +//go:build linux + package syscallf import "syscall" From f596c656de543685f559e22f7f28cb0580ef1429 Mon Sep 17 00:00:00 2001 From: Karol Jakusz-Gostomski Date: Wed, 9 Oct 2024 18:27:46 +0200 Subject: [PATCH 13/13] integer-overflow - no error conversion --- syscallf/rm_watch.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/syscallf/rm_watch.go b/syscallf/rm_watch.go index d7f5152..9024fb3 100644 --- a/syscallf/rm_watch.go +++ b/syscallf/rm_watch.go @@ -4,30 +4,6 @@ package syscallf import "syscall" -// Do the interface allocations only once for common -// Errno values. -var ( - errEAGAIN error = syscall.EAGAIN - errEINVAL error = syscall.EINVAL - errENOENT error = syscall.ENOENT -) - -// errnoErr returns common boxed Errno values, to prevent -// allocations at runtime. -func errnoErr(e syscall.Errno) error { - switch e { - case 0: - return nil - case syscall.EAGAIN: - return errEAGAIN - case syscall.EINVAL: - return errEINVAL - case syscall.ENOENT: - return errENOENT - } - return e -} - func InotifyRmWatch(fd int, watchdesc int) (int, error) { var success int var err error @@ -35,7 +11,7 @@ func InotifyRmWatch(fd int, watchdesc int) (int, error) { r0, _, e1 := syscall.RawSyscall(syscall.SYS_INOTIFY_RM_WATCH, uintptr(fd), uintptr(watchdesc), 0) success = int(r0) if e1 != 0 { - err = errnoErr(e1) + err = e1 } return success, err }