Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix file permission to be 0600 #3563

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ioctl/cmd/contract/contractshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func isDir(path string) bool {

func isReadOnly(path string) bool {
var readOnly = false
file, err := os.OpenFile(filepath.Clean(path), os.O_WRONLY, 0666)
file, err := os.OpenFile(filepath.Clean(path), os.O_WRONLY, 0600)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we need to clarify what the function is doing. isReadyOnly checks whether the file is ready only, if so, why we use os.O_WRONLY? Permission error in line 97 could be either no permission to write or no permission to read
  2. to my understanding, the last 0666 or 0600 has no impact on the function call. it will be used if os.O_CREATE is set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the write permission before sending it to the editor (https://ide.iotex.io/) where user can edit the content of the file. After editing finished, the local file will be updated with the editor syncing file.

if err != nil {
if os.IsPermission(err) {
log.Println("Error: Write permission denied.")
Expand Down Expand Up @@ -255,7 +255,7 @@ func share(args []string) error {
log.Println("mkdir failed: ", err)
break
}
if err := os.WriteFile(setPath, []byte(content), 0644); err != nil {
if err := os.WriteFile(setPath, []byte(content), 0600); err != nil {
log.Println("set file failed: ", err)
break
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func InitLoggers(globalCfg GlobalConfig, subCfgs map[string]GlobalConfig, opts .
return err
}
if cfg.StderrRedirectFile != nil {
stderrF, err := os.OpenFile(*cfg.StderrRedirectFile, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
stderrF, err := os.OpenFile(*cfg.StderrRedirectFile, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func LogCrash(r interface{}) {
}

func writeHeapProfile(path string) {
f, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_RDWR, 0644)
f, err := os.OpenFile(filepath.Clean(path), os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
log.S().Errorf("crashlog: open heap profile error: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion tools/addrgen/internal/cmd/createconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var createConfigCmd = &cobra.Command{
priKeyBytes,
pubKeyBytes,
)
if err := os.WriteFile(_outputFile, []byte(cfgStr), 0666); err != nil {
if err := os.WriteFile(_outputFile, []byte(cfgStr), 0600); err != nil {
log.L().Fatal("failed to write file", zap.Error(err))
}
},
Expand Down