mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-19 03:33:43 +03:00
chcon: avoid redundant context allocations
Since context is verified by security_check_context() it can be used in change_file_context() without converting to context_t every time. * src/chcon.c (change_file_context): Use specified_context directly.
This commit is contained in:
1 parent
e4081e44e0
commit
3106de5c78
1 file changed
+9
-9
+9
-9
@@ -141,7 +141,7 @@ static int
|
||||
change_file_context (int fd, char const *file)
|
||||
{
|
||||
security_context_t file_context = NULL;
|
||||
context_t context;
|
||||
context_t context IF_LINT (= NULL);
|
||||
security_context_t context_string;
|
||||
int errors = 0;
|
||||
|
||||
@@ -170,17 +170,14 @@ change_file_context (int fd, char const *file)
|
||||
|
||||
if (compute_context_from_mask (file_context, &context))
|
||||
return 1;
|
||||
|
||||
context_string = context_str (context);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FIXME: this should be done exactly once, in main. */
|
||||
context = context_new (specified_context);
|
||||
if (!context)
|
||||
abort ();
|
||||
context_string = specified_context;
|
||||
}
|
||||
|
||||
context_string = context_str (context);
|
||||
|
||||
if (file_context == NULL || ! STREQ (context_string, file_context))
|
||||
{
|
||||
int fail = (affect_symlink_referent
|
||||
@@ -195,8 +192,11 @@ change_file_context (int fd, char const *file)
|
||||
}
|
||||
}
|
||||
|
||||
context_free (context);
|
||||
freecon (file_context);
|
||||
if (specified_context == NULL)
|
||||
{
|
||||
context_free (context);
|
||||
freecon (file_context);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user