Skip to content

Commit

Permalink
Fix: Create a unique temp file instead of using any random file name
Browse files Browse the repository at this point in the history
Signed-off-by: GLVS Kiriti <[email protected]>
  • Loading branch information
GLVSKiriti authored and poiana committed Apr 5, 2024
1 parent 785aed5 commit cda10d7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions events/syscall/set_setuid_or_set_setgid_bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ var _ = events.Register(
)

func SetSetuidorSetgidbit(h events.Helper) error {
filename := "created-by-falco-event-generator"
if err := os.WriteFile(filename, nil, 0755); err != nil {
// Create a unique temp file
file, err := os.CreateTemp("", "created-by-falco-event-generator-")
if err != nil {
h.Log().WithError(err).Error("Error Creating an empty file")
return err
}
defer os.Remove(filename) // Remove the file after function return
defer os.Remove(file.Name()) // Remove the file after function return

// Set setuid bit with this command
cmd := exec.Command("chmod", "u+s", filename)
cmd := exec.Command("chmod", "u+s", file.Name())

if err := cmd.Run(); err != nil {
h.Log().WithError(err).Error("Error running chmod commad")
Expand Down

0 comments on commit cda10d7

Please sign in to comment.