]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
CHAOS: prevent crash on failed strdup 42/2342/2
authorScott Griepentrog <scott@griepentrog.com>
Wed, 2 Mar 2016 15:34:10 +0000 (09:34 -0600)
committerScott Griepentrog <sgriepentrog@digium.com>
Wed, 2 Mar 2016 17:59:33 +0000 (11:59 -0600)
This patch avoids crashing on a null pointer
if the strdup() allocation fails.

ASTERISK-25323

Change-Id: I3f67434820ba53b53663efd6cbb42749f4f6c0f5

res/res_pjsip_messaging.c

index 54880dba92ad5ed3760819eb5c65af138e7fe6f5..fe285d8a4fe0d1a3e557ddd4cbabd09aaf219bf9 100644 (file)
@@ -530,6 +530,10 @@ static struct msg_data* msg_data_create(const struct ast_msg *msg, const char *t
        /* Make sure we start with sip: */
        mdata->to = ast_begins_with(to, "sip:") ? ast_strdup(++to) : ast_strdup(to - 3);
        mdata->from = ast_strdup(from);
+       if (!mdata->to || !mdata->from) {
+               ao2_ref(mdata, -1);
+               return NULL;
+       }
 
        /* sometimes from can still contain the tag at this point, so remove it */
        if ((tag = strchr(mdata->from, ';'))) {