From: Kern Sibbald Date: Tue, 24 Apr 2007 10:32:31 +0000 (+0000) Subject: kes Make pm_strxxx() routines handle input of NULL pointer. This X-Git-Tag: Release-7.0.0~6515 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=167a546d2de22ff217f271f7b3e53dda8faf517b;p=bacula%2Fbacula kes Make pm_strxxx() routines handle input of NULL pointer. This is to protect from NULL pointers returned from SQL databases. kes Correct typo in bacula-sd manpage as pointed out by John Goerzen. kes Add more debug to FIFO code -- fix fifo regression test. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4613 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 3a55d440ec..6543dc8233 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -43,26 +43,7 @@ Document: Priority: -- Look at using posix_fadvise(2) for backups -- see bug #751. - Possibly add the code at findlib/bfile.c:795 - -/* TCP socket options */ -#define TCP_NODELAY 1 /* Turn off Nagle's algorithm. */ -#define TCP_MAXSEG 2 /* Limit MSS */ -#define TCP_CORK 3 /* Never send partially complete segments */ -#define TCP_KEEPIDLE 4 /* Start keeplives after this period */ -#define TCP_KEEPINTVL 5 /* Interval between keepalives */ -#define TCP_KEEPCNT 6 /* Number of keepalives before death */ -#define TCP_SYNCNT 7 /* Number of SYN retransmits */ -#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ -#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ -#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ -#define TCP_INFO 11 /* Information about this connection. */ -#define TCP_QUICKACK 12 /* Block/reenable quick acks */ -#define TCP_CONGESTION 13 /* Congestion control algorithm */ - -- Fix bnet_connect() code to set a timer and to use time to - measure the time. +- Implement 4th argument to make_catalog_backup that passes hostname. - the director seg faulted when I omitted the pool directive from a job resource. I was experimenting and thought it redundant that I had @@ -1707,5 +1688,23 @@ Block Position: 0 === Done - Why the heck doesn't bacula drop root priviledges before connecting to the DB? +- Look at using posix_fadvise(2) for backups -- see bug #751. + Possibly add the code at findlib/bfile.c:795 +/* TCP socket options */ +#define TCP_NODELAY 1 /* Turn off Nagle's algorithm. */ +#define TCP_MAXSEG 2 /* Limit MSS */ +#define TCP_CORK 3 /* Never send partially complete segments */ +#define TCP_KEEPIDLE 4 /* Start keeplives after this period */ +#define TCP_KEEPINTVL 5 /* Interval between keepalives */ +#define TCP_KEEPCNT 6 /* Number of keepalives before death */ +#define TCP_SYNCNT 7 /* Number of SYN retransmits */ +#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ +#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ +#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ +#define TCP_INFO 11 /* Information about this connection. */ +#define TCP_QUICKACK 12 /* Block/reenable quick acks */ +#define TCP_CONGESTION 13 /* Congestion control algorithm */ +- Fix bnet_connect() code to set a timer and to use time to + measure the time. diff --git a/bacula/manpages/bacula-sd.8 b/bacula/manpages/bacula-sd.8 index a793f25d55..d765f639c3 100644 --- a/bacula/manpages/bacula-sd.8 +++ b/bacula/manpages/bacula-sd.8 @@ -9,7 +9,7 @@ .B bacula\-sd \- Bacula's Storage Daemon .SH SYNOPSIS -.B bacula\-fd +.B bacula\-sd .RI [ options ] .br .SH DESCRIPTION diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index aaed23ba49..bb1f27a9c9 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -358,9 +358,9 @@ void do_restore(JCR *jcr) * Now determine if we are extracting or not. */ jcr->num_files_examined++; - Dmsg1(30, "Outfile=%s\n", attr->ofname); extract = false; stat = create_file(jcr, attr, &bfd, jcr->replace); + Dmsg2(30, "Outfile=%s create_file stat=%d\n", attr->ofname, stat); switch (stat) { case CF_ERROR: case CF_SKIP: @@ -376,6 +376,7 @@ void do_restore(JCR *jcr) jcr->unlock(); fileAddr = 0; print_ls_output(jcr, attr); + #ifdef HAVE_DARWIN_OS /* Only restore the resource fork for regular files */ from_base64(&rsrc_len, attr->attrEx); @@ -683,8 +684,8 @@ void do_restore(JCR *jcr) bail_out: set_jcr_job_status(jcr, JS_ErrorTerminated); -ok_out: +ok_out: /* Free Signature & Crypto Data */ if (sig) { crypto_sign_free(sig); diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index 0cbf644fda..55eb00fbcc 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -95,7 +95,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) // eliminate invalid windows filename characters from foreign filenames char *ch = (char *)attr->ofname; if (ch[0] != 0 && ch[1] != 0) { - ch+=2; + ch += 2; while (*ch) { switch (*ch) { case ':': @@ -155,6 +155,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) */ if (exists && attr->type != FT_RAW && attr->type != FT_FIFO) { /* Get rid of old copy */ + Dmsg1(400, "unlink %s\n", attr->ofname); if (unlink(attr->ofname) == -1) { berrno be; Qmsg(jcr, M_ERROR, 0, _("File %s already exists and could not be replaced. ERR=%s.\n"), @@ -183,7 +184,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) attr->ofname[pnl] = 0; /* terminate path */ if (!path_already_seen(jcr, attr->ofname, pnl)) { - Dmsg1(100, "Make path %s\n", attr->ofname); + Dmsg1(400, "Make path %s\n", attr->ofname); /* * If we need to make the directory, ensure that it is with * execute bit set (i.e. parent_mode), and preserve what already @@ -228,7 +229,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) case FT_FIFO: /* Bacula fifo to save data */ case FT_SPEC: if (S_ISFIFO(attr->statp.st_mode)) { - Dmsg1(200, "Restore fifo: %s\n", attr->ofname); + Dmsg1(400, "Restore fifo: %s\n", attr->ofname); if (mkfifo(attr->ofname, attr->statp.st_mode) != 0 && errno != EEXIST) { berrno be; Qmsg2(jcr, M_ERROR, 0, _("Cannot make fifo %s: ERR=%s\n"), @@ -238,7 +239,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) } else if (S_ISSOCK(attr->statp.st_mode)) { Dmsg1(200, "Skipping restore of socket: %s\n", attr->ofname); } else { - Dmsg1(200, "Restore node: %s\n", attr->ofname); + Dmsg1(400, "Restore node: %s\n", attr->ofname); if (mknod(attr->ofname, attr->statp.st_mode, attr->statp.st_rdev) != 0 && errno != EEXIST) { berrno be; Qmsg2(jcr, M_ERROR, 0, _("Cannot make node %s: ERR=%s\n"), @@ -246,13 +247,19 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) return CF_ERROR; } } + /* + * Here we are going to attempt to restore to a FIFO, which + * means that the FIFO must already exist, AND there must + * be some process already attempting to read from the + * FIFO, so we open it write-only. + */ if (attr->type == FT_RAW || attr->type == FT_FIFO) { btimer_t *tid; - Dmsg1(200, "FT_RAW|FT_FIFO %s\n", attr->ofname); + Dmsg1(400, "FT_RAW|FT_FIFO %s\n", attr->ofname); mode = O_WRONLY | O_BINARY; /* Timeout open() in 60 seconds */ if (attr->type == FT_FIFO) { - Dmsg0(200, "Set FIFO timer\n"); + Dmsg0(400, "Set FIFO timer\n"); tid = start_thread_timer(pthread_self(), 60); } else { tid = NULL; @@ -260,19 +267,20 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) if (is_bopen(bfd)) { Qmsg1(jcr, M_ERROR, 0, _("bpkt already open fid=%d\n"), bfd->fid); } - Dmsg2(200, "open %s mode=0x%x\n", attr->ofname, mode); + Dmsg2(400, "open %s mode=0x%x\n", attr->ofname, mode); if ((bopen(bfd, attr->ofname, mode, 0)) < 0) { berrno be; be.set_errno(bfd->berrno); Qmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"), attr->ofname, be.strerror()); + Dmsg2(400, "Could not open %s: ERR=%s\n", attr->ofname, be.strerror()); stop_thread_timer(tid); return CF_ERROR; } stop_thread_timer(tid); return CF_EXTRACT; } - Dmsg1(200, "FT_SPEC %s\n", attr->ofname); + Dmsg1(400, "FT_SPEC %s\n", attr->ofname); return CF_CREATED; case FT_LNK: diff --git a/bacula/src/lib/mem_pool.c b/bacula/src/lib/mem_pool.c index 0e6be81d0b..c7036c59bd 100644 --- a/bacula/src/lib/mem_pool.c +++ b/bacula/src/lib/mem_pool.c @@ -458,8 +458,11 @@ void print_memory_pool_stats() {} int pm_strcat(POOLMEM **pm, const char *str) { int pmlen = strlen(*pm); - int len = strlen(str) + 1; + int len; + if (!str) str = ""; + + len = strlen(str) + 1; *pm = check_pool_memory_size(*pm, pmlen + len); memcpy(*pm+pmlen, str, len); return pmlen + len - 1; @@ -468,8 +471,11 @@ int pm_strcat(POOLMEM **pm, const char *str) int pm_strcat(POOLMEM *&pm, const char *str) { int pmlen = strlen(pm); - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + len = strlen(str) + 1; pm = check_pool_memory_size(pm, pmlen + len); memcpy(pm+pmlen, str, len); return pmlen + len - 1; @@ -489,8 +495,11 @@ int pm_strcat(POOLMEM *&pm, POOL_MEM &str) int pm_strcat(POOL_MEM &pm, const char *str) { int pmlen = strlen(pm.c_str()); - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + len = strlen(str) + 1; pm.check_size(pmlen + len); memcpy(pm.c_str()+pmlen, str, len); return pmlen + len - 1; @@ -503,8 +512,11 @@ int pm_strcat(POOL_MEM &pm, const char *str) */ int pm_strcpy(POOLMEM **pm, const char *str) { - int len = strlen(str) + 1; + int len; + if (!str) str = ""; + + len = strlen(str) + 1; *pm = check_pool_memory_size(*pm, len); memcpy(*pm, str, len); return len - 1; @@ -512,8 +524,11 @@ int pm_strcpy(POOLMEM **pm, const char *str) int pm_strcpy(POOLMEM *&pm, const char *str) { - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + len = strlen(str) + 1; pm = check_pool_memory_size(pm, len); memcpy(pm, str, len); return len - 1; @@ -531,7 +546,11 @@ int pm_strcpy(POOLMEM *&pm, POOL_MEM &str) int pm_strcpy(POOL_MEM &pm, const char *str) { - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + + len = strlen(str) + 1; pm.check_size(len); memcpy(pm.c_str(), str, len); return len - 1; @@ -577,8 +596,11 @@ void POOL_MEM::realloc_pm(int32_t size) int POOL_MEM::strcat(const char *str) { int pmlen = strlen(mem); - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + len = strlen(str) + 1; check_size(pmlen + len); memcpy(mem+pmlen, str, len); return pmlen + len - 1; @@ -587,7 +609,11 @@ int POOL_MEM::strcat(const char *str) int POOL_MEM::strcpy(const char *str) { - int len = strlen(str) + 1; + int len; + + if (!str) str = ""; + + len = strlen(str) + 1; check_size(len); memcpy(mem, str, len); return len - 1; diff --git a/bacula/src/version.h b/bacula/src/version.h index b21be432e5..f34fb097da 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.8" -#define BDATE "22 April 2007" -#define LSMDATE "22Apr07" +#define BDATE "24 April 2007" +#define LSMDATE "24Apr07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 3bf0d0539c..b01917258c 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,11 @@ Technical notes on version 2.1 General: +24Apr07 +kes Make pm_strxxx() routines handle input of NULL pointer. This + is to protect from NULL pointers returned from SQL databases. +kes Correct typo in bacula-sd manpage as pointed out by John Goerzen. +kes Add more debug to FIFO code -- fix fifo regression test. 23Apr07 kes Implement posix_fadvise in FD, and for reading spool files in SD. kes Add thread timer to bnet_connect() to break from OS if wait time