Skip to content

Commit

Permalink
integer-overflow - validation conditions update
Browse files Browse the repository at this point in the history
  • Loading branch information
akemrir committed Oct 5, 2024
1 parent 79a1dcf commit d711611
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions inotify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d711611

Please sign in to comment.