]> 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>
Thu, 24 Mar 2022 08:03:03 +0000 (09:03 +0100)
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 929e8a489222e8455ccf06305aac832a66059c62..2d12367414b6210a464f1a3f6a803f8f6040231f 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;
 }