From ae2f7c5dd337fd8f2562663019ab8efd8410631c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 1 May 2008 15:05:06 +0000 Subject: [PATCH] kes Fix strippath so that it does not get a buffer overrun and crash FD. This fixes bug #1078. kes Remove 50 millisec wait in SD that broke debugger. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6864 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/filed/backup.c | 40 +++++++++++++++++++++++------------ bacula/src/findlib/bfile.c | 4 +++- bacula/src/findlib/find_one.c | 15 +++++++------ bacula/src/lib/jcr.c | 2 +- bacula/src/stored/job.c | 14 ++++++++---- bacula/technotes-2.3 | 3 +++ 6 files changed, 52 insertions(+), 26 deletions(-) diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index afe9f84daf..c5275c5f7e 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -1169,9 +1169,9 @@ static bool do_strip(int count, char *in) /* Copy to first path separator -- Win32 might have c: ... */ while (*in && !IsPathSeparator(*in)) { - *out++ = *in++; + out++; in++; } - *out++ = *in++; + out++; in++; numsep++; /* one separator seen */ for (stripped=0; strippedlink_save = get_pool_memory(PM_FNAME); } pm_strcpy(ff_pkt->fname_save, ff_pkt->fname); + if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) { + pm_strcpy(ff_pkt->link_save, ff_pkt->link); + Dmsg2(500, "strcpy link_save=%d link=%d\n", strlen(ff_pkt->link_save), + strlen(ff_pkt->link)); + sm_check(__FILE__, __LINE__, true); + } /* * Strip path. If it doesn't succeed put it back. If @@ -1222,19 +1228,20 @@ void strip_path(FF_PKT *ff_pkt) * Do not strip symlinks. * I.e. if either stripping fails don't strip anything. */ - if (do_strip(ff_pkt->strip_path, ff_pkt->fname)) { - /* Strip links but not symlinks */ - if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) { - pm_strcpy(ff_pkt->link_save, ff_pkt->link); - if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) { - strcpy(ff_pkt->link, ff_pkt->link_save); - strcpy(ff_pkt->fname, ff_pkt->fname_save); - } - } - } else { - strcpy(ff_pkt->fname, ff_pkt->fname_save); + if (!do_strip(ff_pkt->strip_path, ff_pkt->fname)) { + unstrip_path(ff_pkt); + goto rtn; } - Dmsg2(200, "fname=%s stripped=%s\n", ff_pkt->fname_save, ff_pkt->fname); + /* Strip links but not symlinks */ + if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) { + if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) { + unstrip_path(ff_pkt); + } + } + +rtn: + Dmsg3(100, "fname=%s stripped=%s link=%s\n", ff_pkt->fname_save, ff_pkt->fname, + ff_pkt->link); } void unstrip_path(FF_PKT *ff_pkt) @@ -1244,6 +1251,11 @@ void unstrip_path(FF_PKT *ff_pkt) } strcpy(ff_pkt->fname, ff_pkt->fname_save); if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) { + Dmsg2(500, "strcpy link=%s link_save=%s\n", ff_pkt->link, + ff_pkt->link_save); strcpy(ff_pkt->link, ff_pkt->link_save); + Dmsg2(500, "strcpy link=%d link_save=%d\n", strlen(ff_pkt->link), + strlen(ff_pkt->link_save)); + sm_check(__FILE__, __LINE__, true); } } diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 10f867439b..f4c9c7f4be 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -39,6 +39,8 @@ #include "bacula.h" #include "find.h" +const int dbglvl = 200; + int (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL; int (*plugin_bclose)(JCR *jcr) = NULL; ssize_t (*plugin_bread)(JCR *jcr, void *buf, size_t count) = NULL; @@ -830,7 +832,7 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } /* Normal file open */ - Dmsg1(100, "open file %s\n", fname); + Dmsg1(dbglvl, "open file %s\n", fname); /* We use fnctl to set O_NOATIME if requested to avoid open error */ bfd->fid = open(fname, flags & ~O_NOATIME, mode); diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c index a1e8b9075c..576d4c6b88 100644 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -275,8 +275,8 @@ static bool check_changes(JCR *jcr, FF_PKT *ff_pkt) */ if (ff_pkt->incremental && (ff_pkt->statp.st_mtime < ff_pkt->save_time && - ((ff_pkt->flags & FO_MTIMEONLY) || - ff_pkt->statp.st_ctime < ff_pkt->save_time))) + ((ff_pkt->flags & FO_MTIMEONLY) || + ff_pkt->statp.st_ctime < ff_pkt->save_time))) { return false; } @@ -429,8 +429,8 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, lp->ino = ff_pkt->statp.st_ino; lp->dev = ff_pkt->statp.st_dev; bstrncpy(lp->name, fname, len); - lp->next = ff_pkt->linkhash[linkhash]; - ff_pkt->linkhash[linkhash] = lp; + lp->next = ff_pkt->linkhash[linkhash]; + ff_pkt->linkhash[linkhash] = lp; ff_pkt->linked = lp; /* mark saved link */ } else { ff_pkt->linked = NULL; @@ -531,8 +531,11 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, } else { ff_pkt->type = FT_DIRBEGIN; } - /* We have set st_rdev to 1 if it is a reparse point, otherwise 0 */ - if (have_win32_api() && ff_pkt->statp.st_rdev) { + /* + * We have set st_rdev to 1 if it is a reparse point, otherwise 0, + * if st_rdev is 2, it is a mount point + */ + if (have_win32_api() && ff_pkt->statp.st_rdev == 1) { ff_pkt->type = FT_REPARSE; } /* diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 276a29ea68..8fb4f6e1d7 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -694,7 +694,7 @@ void set_jcr_job_status(JCR *jcr, int JobStatus) jcr->wait_time = time(NULL); } } - Dmsg3(100, "jid=%u OnExit JobStatus=%c set=%c\n", (uint32_t)jcr->JobId, + Dmsg3(100, "jid=%u Exit set_jcr_job_status=%c set=%c\n", (uint32_t)jcr->JobId, jcr->JobStatus, JobStatus); } diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index 733f20b042..0b5e6bd4a5 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -165,7 +165,7 @@ bool run_cmd(JCR *jcr) struct timeval tv; struct timezone tz; struct timespec timeout; - int errstat; + int errstat = 0; Dsm_check(1); Dmsg1(200, "Run_cmd: %s\n", jcr->dir_bsock->msg); @@ -187,7 +187,7 @@ bool run_cmd(JCR *jcr) timeout.tv_sec = tv.tv_sec + me->client_wait; Dmsg3(050, "%s waiting %d sec for FD to contact SD key=%s\n", - jcr->Job, (int)me->client_wait, jcr->sd_auth_key); + jcr->Job, (int)(timeout.tv_sec-time(NULL)), jcr->sd_auth_key); /* * Wait for the File daemon to contact us to start the Job, @@ -201,6 +201,8 @@ bool run_cmd(JCR *jcr) break; } } + Dmsg3(100, "Auth=%d canceled=%d errstat=%d\n", jcr->authenticated, + job_canceled(jcr), errstat); V(mutex); memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key)); @@ -220,10 +222,14 @@ void handle_filed_connection(BSOCK *fd, char *job_name) { JCR *jcr; - bmicrosleep(0, 50000); /* wait 50 millisecs */ +/* + * With the following bmicrosleep on, running the + * SD under the debugger fails. + */ +// bmicrosleep(0, 50000); /* wait 50 millisecs */ if (!(jcr=get_jcr_by_full_name(job_name))) { Jmsg1(NULL, M_FATAL, 0, _("FD connect failed: Job name not found: %s\n"), job_name); - Dmsg1(3, "**** Job \"%s\" not found", job_name); + Dmsg1(3, "**** Job \"%s\" not found.\n", job_name); return; } diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 65458204e8..658b1f5117 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -25,6 +25,9 @@ Add long term statistics job table General: 01May08 +kes Fix strippath so that it does not get a buffer overrun and crash FD. + This fixes bug #1078. +kes Remove 50 millisec wait in SD that broke debugger. ebl Add MaxRunSchedTime option that specifies the maximum allowed time that a job may run, counted from when the job was scheduled. ebl Fix MaxWaitTime option that specifies the maximum allowed time that -- 2.39.5