Fix checking bounds of array index after using it; improper sizeof

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
........

Merged revisions 366741 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366746 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Matthew Jordan
2012-05-17 13:21:19 +00:00
parent 2d175b7e8f
commit 87113f1a0c
2 changed files with 4 additions and 3 deletions

View 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))) {