Record bugfixes
(Applies after the other patches)
Passes valgrind.
Record bugfixes:
- all records: do not leak old data on any modification calls
- all records: do not overwrite old data on failure
- user: always check if a role exists when adding it, not only for def_role
- user: properly set def_role on set_roles()
- user: allow deletion of the last role, and properly handle def_role = last_role being deleted
- user: simplify set_defrole to match the other functions
libsemanage/src/seuser_record.c +12 -6
@@ -96,11 +96,13 @@ int semanage_seuser_set_name(semanage_seuser_t * seuser, const char* name) { - seuser->name = strdup(name); -if (!seuser->name) { + char* tmp_name = strdup(name); +if (!tmp_name) {ERR (handle,"out of memory, could not set seuser (Unix) name" );return STATUS_ERR ; } +free (seuser->name); + seuser->name = tmp_name;return STATUS_SUCCESS ; }
@@ -116,11 +118,13 @@ int semanage_seuser_set_sename(semanage_seuser_t * seuser, const char* sename) { - seuser->sename = strdup(sename); -if (!seuser->sename) { + char* tmp_sename = strdup(sename); +if (!tmp_sename) {ERR (handle,"out of memory, could not set seuser (SELinux) name" );return STATUS_ERR ; } +free (seuser->sename); + seuser->sename = tmp_sename;return STATUS_SUCCESS ; }
@@ -136,11 +140,13 @@ int semanage_seuser_set_mlsrange(semanage_seuser_t * seuser, const char* mls_range) { - seuser->mls_range = strdup(mls_range); -if (!seuser->mls_range) { + char* tmp_mls_range = strdup(mls_range); +if (!tmp_mls_range) {ERR (handle,"out of memory, could not set seuser MLS range" );return STATUS_ERR ; } +free (seuser->mls_range); + seuser->mls_range = tmp_mls_range;return STATUS_SUCCESS ; }
libsepol/src/boolean_record.c +4 -2
@@ -82,11 +82,13 @@ int sepol_bool_set_name(sepol_bool_t * boolean, const char* name) { - boolean->name = strdup(name); -if (!boolean->name) { + char* tmp_name = strdup(name); +if (!tmp_name) {ERR (handle,"out of memory, could not set boolean name" );return STATUS_ERR ; } +free (boolean->name); + boolean->name = tmp_name;return STATUS_SUCCESS ; }
libsepol/src/context_record.c +17 -8
@@ -30,12 +30,15 @@ int sepol_context_set_user(sepol_context_t * con, const char* user) { - con->user = strdup(user); -if (!con->user) { + char* tmp_user = strdup(user); +if (!tmp_user) {ERR (handle,"out of memory, could not set " "context user to %s" , user);return STATUS_ERR ; } + +free (con->user); + con->user = tmp_user;return STATUS_SUCCESS ; }
@@ -49,12 +52,14 @@ int sepol_context_set_role(sepol_context_t * con, const char* role) { - con->role = strdup(role); -if (!con->role) { + char* tmp_role = strdup(role); +if (!tmp_role) {ERR (handle,"out of memory, could not set " "context role to %s" , role);return STATUS_ERR ; } +free (con->role); + con->role = tmp_role;return STATUS_SUCCESS ; }
@@ -68,12 +73,14 @@ int sepol_context_set_type(sepol_context_t * con, const char* type) { - con->type = strdup(type); -if (!con->role) { + char* tmp_type = strdup(type); +if (!tmp_type) {ERR (handle,"out of memory, could not set " "context type to %s" , type);return STATUS_ERR ; } +free (con->type); + con->type = tmp_type;return STATUS_SUCCESS ; }
@@ -87,12 +94,14 @@ int sepol_context_set_mls(sepol_context_t * con, const char* mls) { - con->mls = strdup(mls); -if (!con->mls) { + char* tmp_mls = strdup(mls); +if (!tmp_mls) {ERR (handle,"out of memory, could not set " "MLS fields to %s" , mls);return STATUS_ERR ; } +free (con->mls); + con->mls = tmp_mls;return STATUS_SUCCESS ; }
libsepol/src/iface_record.c +6 -2
@@ -109,12 +109,14 @@ int sepol_iface_set_name(sepol_iface_t * iface, const char* name) { - iface->name = strdup(name); -if (!iface->name) { + char* tmp_name = strdup(name); +if (!tmp_name) {ERR (handle,"out of memory, " "could not set interface name" );return STATUS_ERR ; } +free (iface->name); + iface->name = tmp_name;return STATUS_SUCCESS ; }
@@ -127,6 +129,7 @@ void sepol_iface_set_ifcon( sepol_iface_t* iface, sepol_context_t* con) { +sepol_context_free (iface->netif_con); iface->netif_con = con; }
@@ -139,6 +142,7 @@ void sepol_iface_set_msgcon( sepol_iface_t* iface, sepol_context_t* con) { +sepol_context_free (iface->netmsg_con); iface->netmsg_con = con; }
libsepol/src/port_record.c +1 -0
@@ -199,5 +199,6 @@ sepol_context_t* sepol_port_get_con(sepo }void sepol_port_set_con (sepol_port_t * port,sepol_context_t * con) { +sepol_context_free (port->con); port->con = con; }
libsepol/src/user_record.c +67 -52
213 lines not on this page · raw message