From 19233ee789091cb51401fe498af98a8a6f5d056a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 1 Jul 2017 14:46:21 -0400 Subject: [PATCH] Merge pull request #1255 from Hummer12007/policy Prevent null pointer dereferences with policy allocation failure --- sway/commands.c | 6 +++--- sway/commands/permit.c | 6 +++--- sway/security.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index f83b52878..59a6adfba 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -607,10 +607,10 @@ struct cmd_results *config_commands_command(char *exec) { } if (!policy) { policy = alloc_command_policy(cmd); - if (!policy) { - sway_abort("Unable to allocate security policy"); + sway_assert(policy, "Unable to allocate security policy"); + if (policy) { + list_add(config->command_policies, policy); } - list_add(config->command_policies, policy); } policy->context = context; diff --git a/sway/commands/permit.c b/sway/commands/permit.c index 66fa4e2a7..7a5e06f7c 100644 --- a/sway/commands/permit.c +++ b/sway/commands/permit.c @@ -65,11 +65,11 @@ struct cmd_results *cmd_permit(int argc, char **argv) { } struct feature_policy *policy = get_feature_policy(program); - if (assign_perms) { + if (policy && assign_perms) { policy->features |= get_features(argc, argv, &error); + sway_log(L_DEBUG, "Permissions granted to %s for features %d", + policy->program, policy->features); } - sway_log(L_DEBUG, "Permissions granted to %s for features %d", - policy->program, policy->features); free(program); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/security.c b/sway/security.c index 92de06c1d..fcd70f9d6 100644 --- a/sway/security.c +++ b/sway/security.c @@ -152,10 +152,10 @@ struct feature_policy *get_feature_policy(const char *name) { } if (!policy) { policy = alloc_feature_policy(name); - if (!policy) { - sway_abort("Unable to allocate security policy"); + sway_assert(policy, "Unable to allocate security policy"); + if (policy) { + list_add(config->feature_policies, policy); } - list_add(config->feature_policies, policy); } return policy; }