Merge "astfd: Fix buffer overflow in DEBUG_FD_LEAKS."
authorJoshua Colp <jcolp@digium.com>
Thu, 2 Jul 2015 12:51:54 +0000 (07:51 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Thu, 2 Jul 2015 12:51:55 +0000 (07:51 -0500)
channels/chan_mgcp.c
main/channel_internal_api.c

index 16d3c65..d9e182c 100644 (file)
@@ -5007,7 +5007,9 @@ static int unload_module(void)
                return -1;
        }
 
-       close(mgcpsock);
+       if (mgcpsock > -1) {
+               close(mgcpsock);
+       }
        ast_rtp_glue_unregister(&mgcp_rtp_glue);
        ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
        ast_sched_context_destroy(sched);
index 0bb3849..987602d 100644 (file)
@@ -1202,7 +1202,14 @@ void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_nam
 int ast_channel_alert_write(struct ast_channel *chan)
 {
        char blah = 0x7F;
-       return ast_channel_alert_writable(chan) && write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
+
+       if (!ast_channel_alert_writable(chan)) {
+               errno = EBADF;
+               return 0;
+       }
+       /* preset errno in case returned size does not match */
+       errno = EPIPE;
+       return write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
 }
 
 ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
@@ -1253,9 +1260,11 @@ void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
 {
        if (ast_channel_internal_alert_readable(chan)) {
                close(chan->alertpipe[0]);
+               chan->alertpipe[0] = -1;
        }
        if (ast_channel_alert_writable(chan)) {
                close(chan->alertpipe[1]);
+               chan->alertpipe[1] = -1;
        }
 }