]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix checking bounds of array index after using it; improper sizeof
authorMatthew Jordan <mjordan@digium.com>
Thu, 17 May 2012 12:57:30 +0000 (12:57 +0000)
committerMatthew Jordan <mjordan@digium.com>
Thu, 17 May 2012 12:57:30 +0000 (12:57 +0000)
This patch fixes two problems pointed out by a static analysis tool.

* In chan_dahdi, when an event is handled the index of the sub channel is first
  obtained.  In very off nominal cases, the method that determines the index
  can return a negative value.  In the event handling code, whether or not
  the index returned is valid was being checked after that value was used to
  index into an array.  This patch makes it so the value is checked before
  any indexing is done.

* In res_calendar_ews, sizeof was being passed a pointer instead of the struct to
  determine the amount of memory to allocate.

(issue ASTERISK-19651)
Reported by: Matt Jordan

(closes issue ASTERISK-19671)
Reported by: Matt Jordan
........

Merged revisions 366740 from http://svn.asterisk.org/svn/asterisk/branches/1.8

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10@366741 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_dahdi.c
res/res_calendar_ews.c

index 7283d39d190ac64fc8ba96bbb832bf2603f18fc5..85b621882adb3be4ba35cd484f6803c8e99ad5d4 100644 (file)
@@ -7954,6 +7954,9 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast)
        struct ast_frame *f;
 
        idx = dahdi_get_index(ast, p, 0);
+       if (idx < 0) {
+               return &ast_null_frame;
+       }
        mysig = p->sig;
        if (p->outsigmod > -1)
                mysig = p->outsigmod;
@@ -7967,8 +7970,6 @@ static struct ast_frame *dahdi_handle_event(struct ast_channel *ast)
        p->subs[idx].f.data.ptr = NULL;
        f = &p->subs[idx].f;
 
-       if (idx < 0)
-               return &p->subs[idx].f;
        if (p->fake_event) {
                res = p->fake_event;
                p->fake_event = 0;
index d33f4be4fb1c41de67f57b839584c988bf2f9af1..7deca9c97553de5ef31299f19b7606f08b56cbdc 100644 (file)
@@ -233,7 +233,7 @@ static int startelm(void *userdata, int parent, const char *nspace, const char *
                /* Event UID */
                if (ctx->op == XML_OP_FIND) {
                        struct calendar_id *id;
-                       if (!(id = ast_calloc(1, sizeof(id)))) {
+                       if (!(id = ast_calloc(1, sizeof(*id)))) {
                                return NE_XML_ABORT;
                        }
                        if (!(id->id = ast_str_create(256))) {