[asterisk-commits] manager channels.c: Fix allocation failure crash. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 25 22:00:52 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: manager_channels.c: Fix allocation failure crash.
......................................................................


manager_channels.c: Fix allocation failure crash.

An earlier allocation failure failed to create a channel snapshot for the
AMI HangupRequest/SoftHangupRequest event which resulted in a crash in
channel_hangup_request_cb().  Where the stasis message gets generated
cannot tell if the NULL snapshot returned was because of an allocation
failure or the channel was a dummy channel.

* Made channel_hangup_request_cb() check if the channel blob has a
snapshot and exit if it doesn't.

* Eliminated the RAII_VAR usage in channel_hangup_request_cb().

Change-Id: I0b6a1c4e95cbb7d80b2a7054c6eadecc169dfd24
---
M main/manager_channels.c
1 file changed, 16 insertions(+), 8 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve



diff --git a/main/manager_channels.c b/main/manager_channels.c
index da9bf47..c395708 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -697,11 +697,16 @@
 	struct stasis_message *message)
 {
 	struct ast_channel_blob *obj = stasis_message_data(message);
-	RAII_VAR(struct ast_str *, extra, NULL, ast_free);
-	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	struct ast_str *extra;
+	struct ast_str *channel_event_string;
 	struct ast_json *cause;
 	int is_soft;
 	char *manager_event = "HangupRequest";
+
+	if (!obj->snapshot) {
+		/* No snapshot?  Likely an earlier allocation failure creating it. */
+		return;
+	}
 
 	extra = ast_str_create(20);
 	if (!extra) {
@@ -709,16 +714,16 @@
 	}
 
 	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
-
 	if (!channel_event_string) {
+		ast_free(extra);
 		return;
 	}
 
 	cause = ast_json_object_get(obj->blob, "cause");
 	if (cause) {
 		ast_str_append(&extra, 0,
-			       "Cause: %jd\r\n",
-			       ast_json_integer_get(cause));
+			"Cause: %jd\r\n",
+			ast_json_integer_get(cause));
 	}
 
 	is_soft = ast_json_is_true(ast_json_object_get(obj->blob, "soft"));
@@ -727,9 +732,12 @@
 	}
 
 	manager_event(EVENT_FLAG_CALL, manager_event,
-		      "%s%s",
-		      ast_str_buffer(channel_event_string),
-		      ast_str_buffer(extra));
+		"%s%s",
+		ast_str_buffer(channel_event_string),
+		ast_str_buffer(extra));
+
+	ast_free(channel_event_string);
+	ast_free(extra);
 }
 
 static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub,

-- 
To view, visit https://gerrit.asterisk.org/2591
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0b6a1c4e95cbb7d80b2a7054c6eadecc169dfd24
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list