2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 01:57:43 +00:00

Merge parser misc fixes (memory leaks, restoring ostream format)

Closes #533
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1760
Approved-by: Steve Beattie <steve+gitlab@nxnw.org>
Merged-by: Steve Beattie <steve+gitlab@nxnw.org>
This commit is contained in:
Steve Beattie 2025-08-04 22:34:01 -07:00
commit 51bdbec119
5 changed files with 19 additions and 10 deletions

View File

@ -570,6 +570,8 @@ ostream &mnt_rule::dump(ostream &os)
{ {
prefix_rule_t::dump(os); prefix_rule_t::dump(os);
std::ios::fmtflags fmt(os.flags());
if (perms & AA_MAY_MOUNT) if (perms & AA_MAY_MOUNT)
os << "mount"; os << "mount";
else if (perms & AA_MAY_UMOUNT) else if (perms & AA_MAY_UMOUNT)
@ -603,6 +605,7 @@ ostream &mnt_rule::dump(ostream &os)
os << " " << "(0x" << hex << perms << "/0x" << (audit != AUDIT_UNSPECIFIED ? perms : 0) << ")"; os << " " << "(0x" << hex << perms << "/0x" << (audit != AUDIT_UNSPECIFIED ? perms : 0) << ")";
os << ",\n"; os << ",\n";
os.flags(fmt);
return os; return os;
} }

View File

@ -133,8 +133,10 @@ static void process_entries(const void *nodep, VISIT value, int level unused)
if (entry->link_name && if (entry->link_name &&
strncmp((*t)->from, entry->link_name, len) == 0) { strncmp((*t)->from, entry->link_name, len) == 0) {
char *n = do_alias(*t, entry->link_name); char *n = do_alias(*t, entry->link_name);
if (!n) if (!n) {
free_cod_entries(dup);
return; return;
}
if (!dup) if (!dup)
dup = copy_cod_entry(entry); dup = copy_cod_entry(entry);
free(dup->link_name); free(dup->link_name);

View File

@ -188,24 +188,21 @@ cleanup:
if (prof->attachment) { if (prof->attachment) {
tmp = symtab::delete_var(PROFILE_EXEC_VAR); tmp = symtab::delete_var(PROFILE_EXEC_VAR);
delete tmp; delete tmp;
if (saved_exec_path) { if (saved_exec_path)
symtab::add_var(*saved_exec_path); symtab::add_var(*saved_exec_path);
delete saved_exec_path;
}
} }
cleanup_attach: cleanup_attach:
if (prof->attachment) { if (prof->attachment) {
tmp = symtab::delete_var(PROFILE_ATTACH_VAR); tmp = symtab::delete_var(PROFILE_ATTACH_VAR);
delete tmp; delete tmp;
if (saved_attach_path) { if (saved_attach_path)
symtab::add_var(*saved_attach_path); symtab::add_var(*saved_attach_path);
delete saved_attach_path;
}
} }
cleanup_name: cleanup_name:
tmp = symtab::delete_var(PROFILE_NAME_VARIABLE); tmp = symtab::delete_var(PROFILE_NAME_VARIABLE);
delete tmp; delete tmp;
delete saved_exec_path;
delete saved_attach_path;
out: out:
return error; return error;
} }

View File

@ -431,11 +431,14 @@ public:
ostream &dump(ostream &os) override { ostream &dump(ostream &os) override {
class_rule_t::dump(os); class_rule_t::dump(os);
std::ios::fmtflags fmt(os.flags());
if (saved) if (saved)
os << "(0x" << std::hex << perms << "/orig " << saved << ") "; os << "(0x" << std::hex << perms << "/orig " << saved << ") ";
else else
os << "(0x" << std::hex << perms << ") "; os << "(0x" << std::hex << perms << ") ";
os.flags(fmt);
return os; return os;
} }
@ -460,7 +463,11 @@ public:
ostream &dump(ostream &os) override { ostream &dump(ostream &os) override {
class_rule_t::dump(os); class_rule_t::dump(os);
std::ios::fmtflags fmt(os.flags());
os << "(0x" << std::hex << perms << ") "; os << "(0x" << std::hex << perms << ") ";
os.flags(fmt);
return os; return os;
} }

View File

@ -189,7 +189,7 @@ static void trim_trailing_slash(std::string& str)
str.clear(); // str is all '/' str.clear(); // str is all '/'
} }
int copy_value_to_name(std::string value, char **name) int copy_value_to_name(const std::string& value, char **name)
{ {
free(*name); free(*name);
*name = strdup(value.c_str()); *name = strdup(value.c_str());
@ -307,6 +307,7 @@ int variable::expand_variable()
} }
name = variable::process_var(var.c_str()); name = variable::process_var(var.c_str());
variable *ref = symtab::lookup_existing_symbol(name); variable *ref = symtab::lookup_existing_symbol(name);
free(name);
if (!ref) { if (!ref) {
PERROR("Failed to find declaration for: %s\n", var.c_str()); PERROR("Failed to find declaration for: %s\n", var.c_str());
rc = 1; rc = 1;
@ -336,7 +337,6 @@ int variable::expand_variable()
} }
out: out:
free(name);
expanding = false; expanding = false;
return rc; return rc;
} }