]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix places in resources where a negative return value could impact execution
authorMatthew Jordan <mjordan@digium.com>
Tue, 17 Apr 2012 21:10:25 +0000 (21:10 +0000)
committerMatthew Jordan <mjordan@digium.com>
Tue, 17 Apr 2012 21:10:25 +0000 (21:10 +0000)
This patch addresses a number of modules in resources that did not handle the
negative return value from function calls adequately.  This includes:

* res_agi.c: if the result of the read function is a negative number,
indicating some failure, the result would instead be treated as the number
of bytes read.  This patch now treats negative results in the same manner
as an end of file condition, with the exception that it also logs the
error code indicated by the return.

* res_musiconhold.c: if spawn_mp3 fails to assign a file descriptor to srcfd,
and instead assigns a negative value, that file descriptor could later be
passed to functions that require a valid file descriptor.  If spawn_mp3 fails,
we now immediately retry instead of continuing in the logic.

* res_rtp_asterisk.c: if no codec can be matched between two RTP instances
in a peer to peer bridge, we immediately return instead of attempting to
use the codec payload type as an index to determine the appropriate negotiated
codec.

(issue ASTERISK-19655)
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/1863/

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

res/res_agi.c
res/res_musiconhold.c
res/res_rtp_asterisk.c

index 0e3cf66c6667e98ee48823c38bb1cbddc784ed67..4cddfab82102b9520deee8cec93c1e160353d86f 100644 (file)
@@ -1297,9 +1297,9 @@ static enum agi_result launch_asyncagi(struct ast_channel *chan, char *argv[], i
        setup_env(chan, "async", fds[1], 0, 0, NULL);
        /* read the environment */
        res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
-       if (!res) {
-               ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s\n",
-                       chan->name);
+       if (res <= 0) {
+               ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
+                       chan->name, res < 0 ? strerror(errno) : "EOF");
                returnstatus = AGI_RESULT_FAILURE;
                goto async_agi_abort;
        }
@@ -1327,9 +1327,9 @@ static enum agi_result launch_asyncagi(struct ast_channel *chan, char *argv[], i
                         * fd (the pipe), let's read the response.
                         */
                        res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
-                       if (!res) {
-                               ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s\n",
-                                       chan->name);
+                       if (res <= 0) {
+                               ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
+                                       chan->name, res < 0 ? strerror(errno) : "EOF");
                                free_agi_cmd(cmd);
                                returnstatus = AGI_RESULT_FAILURE;
                                goto async_agi_done;
index e033fecad51b58017fd1a6b6379b44836e81c932..33c4b58f7d361dc1c120b631f0d5346cf4fd1b0a 100644 (file)
@@ -642,7 +642,7 @@ static void *monmp3thread(void *data)
                                ast_log(LOG_WARNING, "Unable to spawn mp3player\n");
                                /* Try again later */
                                sleep(500);
-                               pthread_testcancel();
+                               continue;
                        }
                }
                if (class->timer) {
index 0579915b0f368f50eb1ec43d36792d81799a8a2e..6d4eb50198db867ad43247b05f781fa3dede17a1 100644 (file)
@@ -2044,6 +2044,11 @@ static int bridge_p2p_rtp_write(struct ast_rtp_instance *instance, unsigned int
        /* Otherwise adjust bridged payload to match */
        bridged_payload = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(instance1), payload_type.asterisk_format, payload_type.code);
 
+       /* If no codec could be matched between instance and instance1, then somehow things were made incompatible while we were still bridged.  Bail. */
+       if (bridged_payload < 0) {
+               return -1;
+       }
+
        /* If the payload coming in is not one of the negotiated ones then send it to the core, this will cause formats to change and the bridge to break */
        if (!(ast_rtp_instance_get_codecs(instance1)->payloads[bridged_payload].code)) {
                return -1;