[Asterisk-code-review] core: Cleanup ast get hint() usage. (asterisk[14])
Richard Mudgett
asteriskteam at digium.com
Thu Mar 2 21:46:40 CST 2017
Richard Mudgett has uploaded a new change for review. ( https://gerrit.asterisk.org/5117 )
Change subject: core: Cleanup ast_get_hint() usage.
......................................................................
core: Cleanup ast_get_hint() usage.
* manager.c:manager_state_cb() Fix potential use of uninitialized hint[]
if a hint does not exist for the requested extension. Ran into this when
developing a testsuite test. The AMI event ExtensionStatus came out with
the hint header value containing garbage. The AMI event PresenceStatus
also had the same issue.
* manager.c:action_extensionstate() no need to completely initialize the
hint[]. Only initialize the first element.
* pbx.c:ast_add_hint() Remove unnecessary assignment.
* chan_sip.c: Eliminate an unneeded hint[] local variable. We only care
about the return value of ast_get_hint() there.
Change-Id: Ia9a8786f01f93f1f917200f0a50bead0319af97b
---
M channels/chan_sip.c
M main/manager.c
M main/pbx.c
3 files changed, 18 insertions(+), 14 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/5117/1
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c59d510..3859e8f 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -18363,10 +18363,11 @@
/* If this is a subscription we actually just need to see if a hint exists for the extension */
if (req->method == SIP_SUBSCRIBE) {
- char hint[AST_MAX_EXTENSION];
int which = 0;
- if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, uri) ||
- (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, decoded_uri) && (which = 1))) {
+
+ if (ast_get_hint(NULL, 0, NULL, 0, NULL, p->context, uri)
+ || (ast_get_hint(NULL, 0, NULL, 0, NULL, p->context, decoded_uri)
+ && (which = 1))) {
if (!oreq) {
ast_string_field_set(p, exten, which ? decoded_uri : uri);
}
diff --git a/main/manager.c b/main/manager.c
index dcf0d41..91b401c 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -5686,8 +5686,9 @@
{
const char *exten = astman_get_header(m, "Exten");
const char *context = astman_get_header(m, "Context");
- char hint[256] = "";
+ char hint[256];
int status;
+
if (ast_strlen_zero(exten)) {
astman_send_error(s, m, "Extension not specified");
return 0;
@@ -5696,16 +5697,18 @@
context = "default";
}
status = ast_extension_state(NULL, context, exten);
- ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
+ hint[0] = '\0';
+ ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten);
astman_start_ack(s, m);
- astman_append(s, "Message: Extension Status\r\n"
- "Exten: %s\r\n"
- "Context: %s\r\n"
- "Hint: %s\r\n"
- "Status: %d\r\n"
- "StatusText: %s\r\n\r\n",
- exten, context, hint, status,
- ast_extension_state2str(status));
+ astman_append(s, "Message: Extension Status\r\n"
+ "Exten: %s\r\n"
+ "Context: %s\r\n"
+ "Hint: %s\r\n"
+ "Status: %d\r\n"
+ "StatusText: %s\r\n"
+ "\r\n",
+ exten, context, hint, status,
+ ast_extension_state2str(status));
return 0;
}
@@ -6993,6 +6996,7 @@
/* Notify managers of change */
char hint[512];
+ hint[0] = '\0';
ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten);
switch(info->reason) {
diff --git a/main/pbx.c b/main/pbx.c
index 7391dab..24a4a7f 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3966,7 +3966,6 @@
hint_new->last_presence_state = presence_state;
hint_new->last_presence_subtype = subtype;
hint_new->last_presence_message = message;
- message = subtype = NULL;
}
}
--
To view, visit https://gerrit.asterisk.org/5117
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia9a8786f01f93f1f917200f0a50bead0319af97b
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
More information about the asterisk-code-review
mailing list