Merge pull request #584 from rajasec/selinux-errcheck
Added error check in Getfilecon
This commit is contained in:
commit
77d2793c77
|
@ -158,12 +158,14 @@ func Setfilecon(path string, scon string) error {
|
||||||
// Getfilecon returns the SELinux label for this path or returns an error.
|
// Getfilecon returns the SELinux label for this path or returns an error.
|
||||||
func Getfilecon(path string) (string, error) {
|
func Getfilecon(path string) (string, error) {
|
||||||
con, err := system.Lgetxattr(path, xattrNameSelinux)
|
con, err := system.Lgetxattr(path, xattrNameSelinux)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
// Trim the NUL byte at the end of the byte buffer, if present.
|
// Trim the NUL byte at the end of the byte buffer, if present.
|
||||||
if con[len(con)-1] == '\x00' {
|
if len(con) > 0 && con[len(con)-1] == '\x00' {
|
||||||
con = con[:len(con)-1]
|
con = con[:len(con)-1]
|
||||||
}
|
}
|
||||||
return string(con), err
|
return string(con), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setfscreatecon(scon string) error {
|
func Setfscreatecon(scon string) error {
|
||||||
|
|
Loading…
Reference in New Issue