Improve/fix sepol_user_set_roles
- fix set_roles to properly handle num_roles = 0
- simplify a bit...
libsepol/src/user_record.c +24 -19
@@ -209,37 +209,41 @@ int sepol_user_set_roles( size_t num_roles) {size_t i; +char ** tmp_roles =NULL ; +char * tmp_def_role =NULL ; -/* First, make a copy */ -char ** tmp_roles = (char **)calloc (1 ,sizeof (char *) * num_roles); -if (!tmp_roles) - goto omem; +if (num_roles >0 ) { -for (i =0 ; i < num_roles; i++) { - tmp_roles[i] =strdup (roles_arr[i]); -if (!tmp_roles[i]) - goto omem; - } +/* First, make a copy */ + tmp_roles = (char **)calloc (1 ,sizeof (char *) * num_roles); +if (!tmp_roles) + goto omem; -/* Try to set defrole - there should be no failures following -* this call, since the old def role is not saved */ -if (sepol_user_set_defrole (handle, user, tmp_roles[0 ]) <0 ) - goto err; +for (i =0 ; i < num_roles; i++) { + tmp_roles[i] =strdup (roles_arr[i]); +if (!tmp_roles[i]) + goto omem; + } + tmp_def_role =strdup (tmp_roles[0 ]); +if (!tmp_def_role) + goto omem; + } +/* Apply other changes */ for (i =0 ; i < user->num_roles; i++)free (user->roles[i]);free (user->roles); +free (user->def_role); user->roles = tmp_roles; user->num_roles = num_roles; + user->def_role = tmp_def_role; +return STATUS_SUCCESS ; omem: -ERR (handle,"out of memory" ); - - err: -ERR (handle,"could not " -"allocate roles array for user %s" , user->name); +ERR (handle,"out of memory, could not allocate roles array for" +"user %s" , user->name);if (tmp_roles) {for (i =0 ; i < num_roles; i++ ) {
@@ -247,8 +251,9 @@ int sepol_user_set_roles(break ;free (tmp_roles[i]); } -free (tmp_roles); } +free (tmp_roles); +free (tmp_def_role);return STATUS_ERR ; }
Quoted 2 lines · Ivan Gyurdiev
- fix
set_rolesto properly handlenum_roles= 0
- simplify a bit...
Merged all 5 patches (record interfaces, dbase flush, common database, record bugfixes, set roles) as of libsepol 1.9.34 and libsemanage 1.3.39.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.