]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
chcon: use security_check_context() for context validation
authorNamhyung Kim <namhyung@gmail.com>
Mon, 30 Jun 2014 15:12:41 +0000 (00:12 +0900)
committerPádraig Brady <P@draigBrady.com>
Tue, 1 Jul 2014 14:45:53 +0000 (15:45 +0100)
context_new() and _free() are used for checking validity of a
specified context.  libselinux provides security_check_context
for this purpose so use it.

Note that context_new() can fail for a valid context - e.g. ENOMEM.

* src/chcon.c (main): Use security_check_context().

src/chcon.c

index 32d4b0f8b7aa98830ec6404c83801c5115f29854..8c18167ffb92e6169f233edb7a552b9a89868197 100644 (file)
@@ -555,13 +555,10 @@ main (int argc, char **argv)
     }
   else
     {
-      context_t context;
       specified_context = argv[optind++];
-      context = context_new (specified_context);
-      if (!context)
-        error (EXIT_FAILURE, 0, _("invalid context: %s"),
+      if (security_check_context (specified_context) < 0)
+        error (EXIT_FAILURE, errno, _("invalid context: %s"),
                quotearg_colon (specified_context));
-      context_free (context);
     }
 
   if (reference_file && component_specified)