]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #6599 About a segfault in the Director with debuglevel >= 900
authorAlain Spineux <alain@baculasystems.com>
Thu, 16 Jul 2020 08:23:47 +0000 (10:23 +0200)
committerEric Bollengier <eric@baculasystems.com>
Tue, 1 Mar 2022 14:36:16 +0000 (15:36 +0100)
- globals can be NULL when called from dump_each_resource()
  in parse_config()
- the dump is called from inside the parser, before the globals
  are initialized
- No other solution than checking "globals" inside the getNumConcurrentXX()
  and isEnable() methods

bacula/src/dird/dird_conf.c

index e3306b60a9495df6178b67521e986f3b1b5c0baa..6fcdd6201e28ff3abdd9854b310174c96a6d1824 100644 (file)
@@ -106,6 +106,10 @@ void CLIENT::create_client_globals()
 int32_t CLIENT::getNumConcurrentJobs()
 {
    LOCK_GUARD(globals_mutex);
+   if (globals == NULL) {
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
+      return 0;
+   }
    return globals->NumConcurrentJobs;
 }
 
@@ -176,7 +180,9 @@ void CLIENT::setAddress(char *addr)
 bool CLIENT::is_enabled()
 {
    LOCK_GUARD(globals_mutex);
-   if (globals->enabled < 0) { /* not yet modified, use default from resource */
+   if (globals == NULL || globals->enabled < 0) {
+      /* not yet modified, use default from resource */
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
       return Enabled;
    }
    return globals->enabled;
@@ -204,6 +210,10 @@ void JOB::create_job_globals()
 int32_t JOB::getNumConcurrentJobs()
 {
    LOCK_GUARD(globals_mutex);
+   if (globals == NULL) {
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
+      return 0;
+   }
    return globals->NumConcurrentJobs;
 }
 
@@ -221,7 +231,9 @@ int32_t JOB::incNumConcurrentJobs(int32_t inc)
 bool JOB::is_enabled()
 {
    LOCK_GUARD(globals_mutex);
-   if (globals->enabled < 0) { /* not yet modified, use default from resource */
+   if (globals == NULL || globals->enabled < 0) {
+      /* not yet modified, use default from resource */
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
       return Enabled;
    }
    return globals->enabled;
@@ -248,6 +260,10 @@ void STORE::create_store_globals()
 int32_t STORE::getNumConcurrentReadJobs()
 {
    LOCK_GUARD(globals_mutex);
+   if (globals == NULL) {
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
+      return 0;
+   }
    return globals->NumConcurrentReadJobs;
 }
 
@@ -265,6 +281,10 @@ int32_t STORE::incNumConcurrentReadJobs(int32_t inc)
 int32_t STORE::getNumConcurrentJobs()
 {
    LOCK_GUARD(globals_mutex);
+   if (globals == NULL) {
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
+      return 0;
+   }
    return globals->NumConcurrentJobs;
 }
 
@@ -282,7 +302,9 @@ int32_t STORE::incNumConcurrentJobs(int32_t inc)
 bool STORE::is_enabled()
 {
    LOCK_GUARD(globals_mutex);
-   if (globals->enabled < 0) { /* not yet modified, use default from resource */
+   if (globals == NULL || globals->enabled < 0) {
+      /* not yet modified, use default from resource */
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
       return Enabled;
    }
    return globals->enabled;
@@ -309,7 +331,9 @@ void SCHED::create_sched_globals()
 bool SCHED::is_enabled()
 {
    LOCK_GUARD(globals_mutex);
-   if (globals->enabled < 0) { /* not yet modified, use default from resource */
+   if (globals == NULL || globals->enabled < 0) {
+      /* not yet modified, use default from resource */
+      /* globals can be NULL when called from dump_each_resource() in parse_config() */
       return Enabled;
    }
    return globals->enabled;