selinux: Adds a check for a NUL byte at the end of the string and removes

it.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2015-03-11 14:10:37 -04:00
parent 43fabe36d1
commit a9442e6660
1 changed files with 5 additions and 0 deletions

View File

@ -159,6 +159,11 @@ func Setfilecon(path string, scon string) error {
// Getfilecon returns the SELinux label for this path or returns an error.
func Getfilecon(path string) (string, error) {
con, err := system.Lgetxattr(path, xattrNameSelinux)
// Trim the NUL byte at the end of the byte buffer, if present.
if con[len(con)-1] == '\x00' {
con = con[:len(con)-1]
}
return string(con), err
}