2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

parser: parser clean up add_named_transition()

The add_named_transition function was written in a way that is difficult
to understand while attempting to read the function. This patch attempts
to clean it up.

First, this patch removes this confusing code flow issue:

  if (!entry->ns) { ... }
  if (entry->ns) { ... } else { ... }

It then unifies the way that the ns and nt_name strings of the cod_entry
struct are handled prior to calling add_entry_to_x_table() and/or
returning. ns and nt_name are now guaranteed to be NULL before
performing either of those actions.

Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Acked-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
Tyler Hicks
2016-03-18 17:28:50 -05:00
parent f8535c1d09
commit 280b6107a6

View File

@@ -118,10 +118,16 @@ static int add_named_transition(Profile *prof, struct cod_entry *entry)
}
sprintf(name, "%s//%s", prof->name, entry->nt_name);
free(entry->nt_name);
entry->nt_name = name;
entry->nt_name = NULL;
} else {
/**
* pass control of the memory pointed to by nt_name
* from entry to add_entry_to_x_table()
*/
name = entry->nt_name;
entry->nt_name = NULL;
}
}
if (entry->ns) {
} else {
name = (char *) malloc(strlen(entry->ns) + strlen(entry->nt_name) + 3);
if (!name) {
PERROR("Memory allocation error\n");
@@ -132,8 +138,6 @@ static int add_named_transition(Profile *prof, struct cod_entry *entry)
free(entry->nt_name);
entry->ns = NULL;
entry->nt_name = NULL;
} else {
name = entry->nt_name;
}
return add_entry_to_x_table(prof, name);
@@ -164,8 +168,6 @@ void post_process_file_entries(Profile *prof)
mode |= SHIFT_MODE(n << 10, AA_OTHER_SHIFT);
entry->mode = ((entry->mode & ~AA_ALL_EXEC_MODIFIERS) |
(mode & AA_ALL_EXEC_MODIFIERS));
entry->ns = NULL;
entry->nt_name = NULL;
}
/* FIXME: currently change_profile also implies onexec */
cp_mode |= entry->mode & (AA_CHANGE_PROFILE);