Skip to content

Commit

Permalink
add check for GID overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
taigrr committed Feb 14, 2025
1 parent 31ef1bb commit 210a32c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ingredients/file/fileDirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io/fs"
"math"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -130,7 +131,15 @@ func (f File) directory(ctx context.Context, test bool) (types.Result, error) {
Succeeded: false, Failed: true, Notes: notes,
}, lookupErr
}
gid, parseErr := strconv.ParseUint(group.Gid, 10, 32)
uGID, parseErr := strconv.ParseUint(group.Gid, 10, 32)
if uGID > math.MaxInt32 {
notes = append(notes, types.Snprintf("gid %d is too large", uGID))
return types.Result{
Succeeded: false, Failed: true, Notes: notes,
}, parseErr
}
gid := int(uGID)

if parseErr != nil {
return types.Result{
Succeeded: false, Failed: true, Notes: notes,
Expand Down Expand Up @@ -212,12 +221,19 @@ func (f File) directory(ctx context.Context, test bool) (types.Result, error) {
Succeeded: false, Failed: true, Notes: notes,
}, lookupErr
}
gid, parseErr := strconv.ParseUint(group.Gid, 10, 32)
uGID, parseErr := strconv.ParseUint(group.Gid, 10, 32)
if parseErr != nil {
return types.Result{
Succeeded: false, Failed: true,
}, parseErr
}
if uGID > math.MaxInt32 {
notes = append(notes, types.Snprintf("gid %d is too large", uGID))
return types.Result{
Succeeded: false, Failed: true, Notes: notes,
}, parseErr
}
gid := int(uGID)
if test {
notes = append(notes, types.Snprintf("would chown %s to %s", name, d.group))
} else {
Expand Down

0 comments on commit 210a32c

Please sign in to comment.