Blob Blame History Raw
From: Razvan Crainea <razvan@opensips.org>
Date: Tue, 24 Oct 2017 11:30:20 +0300
Subject: [PATCH] db: do not compute capabilities

Do not compute capabilities for modules that pre-populate them. This
fixes an issue where the db engine was overwriting the db capabilities
of db_virtual.

Thanks go to Jonathan Hulme for reporting and providing testing
environment

(cherry picked from commit 0527560978028de80a51343714429e5a3d923919)

diff --git a/db/db.c b/db/db.c
index f658a0b13..a05406761 100644
--- a/db/db.c
+++ b/db/db.c
@@ -244,7 +244,10 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
 		dbf.insert_update = (db_insert_update_f)find_mod_export(tmp,
 			"db_insert_update", 2, 0);
 	}
-	if(db_check_api(&dbf, tmp)!=0)
+	/* check if the module pre-populated the capabilities, or we need to
+	 * compute them ourselves - we check for the INSERT capability, because
+	 * it's the only one that should be exported by all modules */
+	if(!DB_CAPABILITY(dbf, DB_CAP_INSERT) && db_check_api(&dbf, tmp)!=0)
 		goto error;
 
 	*mydbf=dbf; /* copy */