Skip to content

os: chmod could report if mode bits that are not in use are provided #44575

@kevlar700

Description

@kevlar700

What version of Go are you using (go version)?

go version go1.16rc1 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using linux/amd64

What did you expect to see?

A directory with drwxrwxrwt

What did you see instead?

drwxrwxrwx
Incorrect permission bit (missing t)

Proposal

Chmod could return an error, if bits are supplied that are not in use.

This could point users to the documentation that alternatively could be improved (currently an iota source copy) and also protect users to a degree, that fail to use an octal literal notation e.g. 1777 like the chmod command line binary instead of 01777

I assume to some degree that os.chmod could return an error upon use of certain or ideally, all unused bits. Those bits could be reclaimed if needed in the future and consideration of user behaviour, considered before new bit assignments?

if (mode & 0o1000) != 0 {
   return errors.New("the supplied os.FileMode contains a unix sticky bit that is not currently in use, use os.ModeSticky ")
}

//Or along the lines of the following (sticky, sgid and suid) but perhaps for all unused bits.

if (mode & 0o7000) != 0 {
   return errors.New("the supplied os.FileMode contains a bit that is not currently in use, go chmod differs from unix chmod")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions