[git commit] stat: fix printing selinux context and null-dereference

Denys Vlasenko vda.linux at googlemail.com
Fri Jun 27 12:08:29 UTC 2014

commit: http://git.busybox.net/busybox/commit/?id=1b487ea8a69ac90b530e9ccd161a5b1b21e604c7
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

busybox stat tries to always print the selinux context, even if it
is not requested which leads to a segmentation fault due to
dereferencing a null-pointer.

This also changes the format-string used to print the context to
so it actually produces useful output.

Signed-off-by: Michael Gernoth <michael at gernoth.net>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
 coreutils/stat.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/coreutils/stat.c b/coreutils/stat.c
index dc9d81c..769fac0 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -655,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
 		if (option_mask32 & OPT_SELINUX)
-			printf(" %lc\n", *scontext);
+			printf(" %s\n", scontext);
 # endif
@@ -700,7 +700,8 @@ static bool do_stat(const char *filename, const char *format)
 		       (unsigned long) statbuf.st_gid,
 		       (gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
-		printf("   S_Context: %lc\n", *scontext);
+		if (option_mask32 & OPT_SELINUX)
+			printf("   S_Context: %s\n", scontext);
 # endif
 		printf("Access: %s\n", human_time(statbuf.st_atime));
 		printf("Modify: %s\n", human_time(statbuf.st_mtime));

More information about the busybox-cvs mailing list