Description: Bug in database locking code causes concurrency problems and job failures (patch attached)
Author: Phil Stracchino <phils@caerllewys.net>
Author: Martin Simmons <martin@lispworks.com>
Last-Update: 2021-01-19
Forwarded: not-needed

In Bacula 9.6.4, the following code change was made at src/dird/dird.c:1268 :

- strncpy(catalog->db_driver, BDB_db_driver, db_driver_len);
+ bstrncpy(catalog->db_driver, BDB_db_driver, db_driver_len);

It was not noticed at the time that this introduced an off-by-one error that
led to a bug in DB driver definition which prevents reuse of the BDB object,
leading to unexpected concurrency between jobs, leading in turn to job failures
due to race conditions writing to the database.

The fix is to change that line to:

bstrncpy(catalog->db_driver, BDB_db_driver, db_driver_len+1);

--- a/src/dird/dird.c	2021-01-19 15:25:16.233573546 -0500
+++ b/src/dird/dird.c	2021-01-19 15:26:23.884070798 -0500
@@ -1263,11 +1263,11 @@
          }
          if (catalog->db_driver) {
            /* To copy dbdriver field into "CAT" catalog resource class (local)
             * from dbdriver in "BDB" catalog DB Interface class (global)
             */
-            bstrncpy(catalog->db_driver, BDB_db_driver, db_driver_len);
+            bstrncpy(catalog->db_driver, BDB_db_driver, db_driver_len+1);
          }
       }
 
       if (!db || !db_open_database(NULL, db)) {
          Pmsg2(000, _("Could not open Catalog \"%s\", database \"%s\".\n"),
