]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #7998 About dir crashing for client intiated backup
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Tue, 10 Aug 2021 10:51:06 +0000 (12:51 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 11 Aug 2021 09:04:34 +0000 (11:04 +0200)
Description:
For client initiated backup, ua->UA_sock == jcr->file_bsock, see
(ua_run.c:275):
if (rc.fdcalled) {
      jcr->file_bsock = ua->UA_sock;
      jcr->file_bsock->set_jcr(jcr);
}

So when jcr is freed, the ua->UA_sock which is used by ua->error_msg
and others, is no longer valid.

bacula/src/dird/ua_run.c

index 01f7afbc7f410a83d836b6a7cd40a126ee4ab3f0..a0086bcbfbd7780be359fee80e1a3766b23a1462 100644 (file)
@@ -303,18 +303,26 @@ static JobId_t start_job(UAContext *ua, JCR *jcr, run_ctx &rc)
    }
    Dmsg4(100, "JobId=%u NewJobId=%d pool=%s priority=%d\n", (int)jcr->JobId,
          JobId, jcr->pool->name(), jcr->JobPriority);
-   free_jcr(jcr);                  /* release jcr */
    if (JobId == 0) {
       ua->error_msg(_("Job %s failed.\n"), edit_int64(rc.jr.JobId, ed1));
 
    } else {
       ua->send_msg(_("Job queued. JobId=%s\n"), edit_int64(JobId, ed1));
    }
+
    if (rc.fdcalled) {
-      ua->signal(BNET_FDCALLED); /* After this point, this is a new connection */
-      ua->UA_sock = new_bsock();
+      if (JobId != 0) {
+         ua->signal(BNET_FDCALLED); /* After this point, this is a new connection */
+         ua->UA_sock = new_bsock();
+      } else {
+         /* Job failed to start, socket can be reset here so that we won't free ua->UA_socket*/
+         jcr->file_bsock = NULL;
+      }
       ua->quit = true;
    }
+
+   free_jcr(jcr);                  /* release jcr */
+
    return JobId;
 }