From 039d25c341eaa2a5fccda3d1e996e3adadbf7dcc Mon Sep 17 00:00:00 2001 From: rajasec Date: Mon, 22 Feb 2016 13:27:51 +0530 Subject: [PATCH] Added error check in Getfilecon Signed-off-by: rajasec Fixed review comments Signed-off-by: rajasec Fixed review comments for adding length check Signed-off-by: rajasec Fixed review comment Signed-off-by: rajasec --- libcontainer/selinux/selinux.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libcontainer/selinux/selinux.go b/libcontainer/selinux/selinux.go index 88d612ca..3bdce10c 100644 --- a/libcontainer/selinux/selinux.go +++ b/libcontainer/selinux/selinux.go @@ -158,12 +158,14 @@ 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) - + if err != nil { + return "", err + } // 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] } - return string(con), err + return string(con), nil } func Setfscreatecon(scon string) error {