[Asterisk-code-review] pjproject bundled: Add patch for pj atomic crashes (asterisk[master])

George Joseph asteriskteam at digium.com
Sun Mar 25 13:54:54 CDT 2018


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/8666


Change subject: pjproject_bundled:  Add patch for pj_atomic crashes
......................................................................

pjproject_bundled:  Add patch for pj_atomic crashes

There have been some crashes in the past where something attempts
to use a pj_atomic after it's already been destroyed.  This patch
tries to prevent it by making sure that pj_atomic_destroy sets
its mutex to NULL when it's done.  The pj_mutex functions already check
for a NULL mutex and just return PJ_EINVAL.

Change-Id: Id25f70b79fdedf44ead6e6e1763a4417d3b3f825
---
A third-party/pjproject/patches/0070-os_core_unix-Set-mutex-NULL-in-atomic-destroy-and-ad.patch
1 file changed, 83 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/8666/1

diff --git a/third-party/pjproject/patches/0070-os_core_unix-Set-mutex-NULL-in-atomic-destroy-and-ad.patch b/third-party/pjproject/patches/0070-os_core_unix-Set-mutex-NULL-in-atomic-destroy-and-ad.patch
new file mode 100644
index 0000000..a568fe6
--- /dev/null
+++ b/third-party/pjproject/patches/0070-os_core_unix-Set-mutex-NULL-in-atomic-destroy-and-ad.patch
@@ -0,0 +1,83 @@
+From 1ffa1dcff0126d9e3d9c783f981261eb32ff6d00 Mon Sep 17 00:00:00 2001
+From: George Joseph <gjoseph at digium.com>
+Date: Sun, 25 Mar 2018 11:59:49 -0600
+Subject: [PATCH] os_core_unix: Set mutex = NULL in atomic destroy and add more
+ checks
+
+The pj_mutex functions all check for NULL mutexes but pj_atomic_destroy
+wasn't setting its mutex to NULL after it destroyed it so attempts
+to use the atomic again would cause a crash.  This doesn't address
+why an apptempt was made to use the atomic again but it does prevent the
+crash.
+
+Also added a few other checks to the atomic functions.
+---
+ pjlib/src/pj/os_core_unix.c | 19 +++++++++++++++++--
+ 1 file changed, 17 insertions(+), 2 deletions(-)
+
+diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
+index ebfe84348..085e4bd13 100644
+--- a/pjlib/src/pj/os_core_unix.c
++++ b/pjlib/src/pj/os_core_unix.c
+@@ -879,9 +879,15 @@ PJ_DEF(pj_status_t) pj_atomic_create( pj_pool_t *pool,
+  */
+ PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var )
+ {
++    pj_status_t status;
++
+     PJ_ASSERT_RETURN(atomic_var, PJ_EINVAL);
+ #if PJ_HAS_THREADS
+-    return pj_mutex_destroy( atomic_var->mutex );
++    status = pj_mutex_destroy( atomic_var->mutex );
++    if (status == PJ_SUCCESS) {
++        atomic_var->mutex = NULL;
++    }
++    return status;
+ #else
+     return 0;
+ #endif
+@@ -892,10 +898,16 @@ PJ_DEF(pj_status_t) pj_atomic_destroy( pj_atomic_t *atomic_var )
+  */
+ PJ_DEF(void) pj_atomic_set(pj_atomic_t *atomic_var, pj_atomic_value_t value)
+ {
++    pj_status_t status;
++
+     PJ_CHECK_STACK();
++    PJ_ASSERT_RETURN(atomic_var, ; );
+ 
+ #if PJ_HAS_THREADS
+-    pj_mutex_lock( atomic_var->mutex );
++    status = pj_mutex_lock( atomic_var->mutex );
++    if (status != PJ_SUCCESS) {
++        return;
++    }
+ #endif
+     atomic_var->value = value;
+ #if PJ_HAS_THREADS
+@@ -946,6 +958,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var)
+  */
+ PJ_DEF(void) pj_atomic_inc(pj_atomic_t *atomic_var)
+ {
++    PJ_ASSERT_RETURN(atomic_var, ; );
+     pj_atomic_inc_and_get(atomic_var);
+ }
+ 
+@@ -974,6 +987,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var)
+  */
+ PJ_DEF(void) pj_atomic_dec(pj_atomic_t *atomic_var)
+ {
++    PJ_ASSERT_RETURN(atomic_var, ; );
+     pj_atomic_dec_and_get(atomic_var);
+ }
+ 
+@@ -1005,6 +1019,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,
+ PJ_DEF(void) pj_atomic_add( pj_atomic_t *atomic_var,
+                             pj_atomic_value_t value )
+ {
++    PJ_ASSERT_RETURN(atomic_var, ; );
+     pj_atomic_add_and_get(atomic_var, value);
+ }
+ 
+-- 
+2.14.3
+

-- 
To view, visit https://gerrit.asterisk.org/8666
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id25f70b79fdedf44ead6e6e1763a4417d3b3f825
Gerrit-Change-Number: 8666
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180325/96f3cd21/attachment.html>


More information about the asterisk-code-review mailing list