]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix race in astdb
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 17 Mar 2009 05:50:52 +0000 (05:50 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 17 Mar 2009 05:50:52 +0000 (05:50 +0000)
The underlying db1 implementation does not fully isolate the pages retrieved
from astdb, so the lock protecting accesses needs to be extended until the
copy from the shared memory structure is done.
(closes issue #14682)
 Reported by: makoto

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

main/db.c

index 3e61be50950e5b9e8597f1cf2d166905e0043b8b..9da3a11dd958455ff0d553aa62949ad2d06a181e 100644 (file)
--- a/main/db.c
+++ b/main/db.c
@@ -187,10 +187,8 @@ int ast_db_get(const char *family, const char *keys, char *value, int valuelen)
        memset(value, 0, valuelen);
        key.data = fullkey;
        key.size = fullkeylen + 1;
-       
+
        res = astdb->get(astdb, &key, &data, 0);
-       
-       ast_mutex_unlock(&dblock);
 
        /* Be sure to NULL terminate our data either way */
        if (res) {
@@ -208,6 +206,11 @@ int ast_db_get(const char *family, const char *keys, char *value, int valuelen)
                        ast_log(LOG_NOTICE, "Strange, empty value for /%s/%s\n", family, keys);
                }
        }
+
+       /* Data is not fully isolated for concurrency, so the lock must be extended
+        * to after the copy to the output buffer. */
+       ast_mutex_unlock(&dblock);
+
        return res;
 }