]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix new compiler warnings + always use bstrncpy not strncpy to ensure EOS at end...
authorKern Sibbald <kern@sibbald.com>
Tue, 12 May 2020 15:27:58 +0000 (17:27 +0200)
committerKern Sibbald <kern@sibbald.com>
Tue, 12 May 2020 15:27:58 +0000 (17:27 +0200)
25 files changed:
bacula/src/baconfig.h
bacula/src/cats/bvfs.c
bacula/src/console/console.c
bacula/src/dird/dird.c
bacula/src/dird/inc_conf.c
bacula/src/dird/restore.c
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_label.c
bacula/src/dird/ua_prune.c
bacula/src/dird/ua_run.c
bacula/src/filed/job.c
bacula/src/filed/restore.c
bacula/src/findlib/bfile.c
bacula/src/findlib/find.c
bacula/src/findlib/find_one.c
bacula/src/lib/bsys.c
bacula/src/lib/htable.c
bacula/src/lib/ini.c
bacula/src/lib/message.c
bacula/src/lib/util.c
bacula/src/plugins/fd/bpipe-fd.c
bacula/src/plugins/fd/test-plugin-fd.c
bacula/src/stored/status.c
bacula/src/tools/fstype.c
bacula/src/tools/testfind.c

index 939406149b2fe682b5c3bca2ca45a3b3f11b20f1..ee47292a499c28f741ed10f531914d914ea377f8 100644 (file)
@@ -546,6 +546,8 @@ int  m_msg(const char *file, int line, POOLMEM **msgbuf, const char *fmt,...);
 int  m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...);
 void t_msg(const char *file, int line, int64_t level, const char *fmt,...);
 
+/* Use bstrncpy instead of strncpy because it ensures last char is a 0 */
+#define strncpy bad_call_on_strncpy_use_bstrncpy
 
 /** Use our strdup with smartalloc */
 #ifndef HAVE_WXCONSOLE
index e5c21835f0f59952dda435af6ceb969ac5d9e882..b3269423dbbe2b581aff6df11e500c3ac149c627 100644 (file)
@@ -342,7 +342,7 @@ static void build_path_hierarchy(JCR *jcr, BDB *mdb,
    char pathid[50];
    ATTR_DBR parent;
    char *bkp = mdb->path;
-   strncpy(pathid, org_pathid, sizeof(pathid));
+   bstrncpy(pathid, org_pathid, sizeof(pathid));
 
    /* Does the ppathid exist for this ? we use a memory cache...  In order to
     * avoid the full loop, we consider that if a dir is allready in the
index 87853615ac60e6897cb12061b87d9244e0b1d2dd..365a8c0d03cd02fd1cca39e6741ce08213ac5533 100644 (file)
@@ -488,9 +488,7 @@ static ItemList *items = NULL;
 void init_items()
 {
    if (!items) {
-      items = (ItemList*) malloc(sizeof(ItemList));
-      memset(items, 0, sizeof(ItemList));
-
+      items = (ItemList*)bmalloc(sizeof(ItemList));  /* bmalloc clears memory */
    } else {
       items->list.destroy();
    }
@@ -1259,7 +1257,7 @@ int main(int argc, char *argv[])
       exit(0);
    }
 
-   memset(&jcr, 0, sizeof(jcr));
+   memset((void *)&jcr, 0, sizeof(jcr));
 
    (void)WSA_Init();                        /* Initialize Windows sockets */
 
index fdb1d97bf97da6a046cc409afaf79de99a1e394d..11c4406ea7d664b4ab0c5382cae722cfff2ada19 100644 (file)
@@ -1265,7 +1265,7 @@ static bool check_catalog(cat_op mode)
            /* To copy dbdriver field into "CAT" catalog resource class (local)
             * from dbdriver in "BDB" catalog DB Interface class (global)
             */
-            strncpy(catalog->db_driver, BDB_db_driver, db_driver_len);
+            bstrncpy(catalog->db_driver, BDB_db_driver, db_driver_len);
          }
       }
 
index b8d42415932e1ceb9f5a74999f8eb2a5dbecfab0..6cdce90bce60d358349929808606e14ab379ccff 100644 (file)
@@ -387,7 +387,7 @@ static void store_newinc(LEX *lc, RES_ITEM *item, int index, int pass)
    }
    if (pass == 1) {
       incexe = (INCEXE *)malloc(sizeof(INCEXE));
-      memcpy(incexe, &res_incexe, sizeof(INCEXE));
+      memcpy((void *)incexe, (void *)&res_incexe, sizeof(INCEXE));
       bmemset(&res_incexe, 0, sizeof(INCEXE));
       if (item->code == 0) { /* include */
          if (res_all.res_fs.num_includes == 0) {
index a09daa432b41c4bf62901eaf134e6b38d8c77eba..c9a0f1278af88f182d613754a75d1c59f64bb009 100644 (file)
@@ -147,7 +147,7 @@ static bool open_bootstrap_file(JCR *jcr, bootstrap_info &info)
    if (!jcr->RestoreBootstrap) {
       return false;
    }
-   strncpy(info.storage, jcr->rstore->name(), MAX_NAME_LENGTH);
+   bstrncpy(info.storage, jcr->rstore->name(), MAX_NAME_LENGTH);
 
    bs = bfopen(jcr->RestoreBootstrap, "rb");
    if (!bs) {
@@ -166,7 +166,7 @@ static bool open_bootstrap_file(JCR *jcr, bootstrap_info &info)
          continue;
       }
       if (!strcasecmp(ua->argk[0], "Storage")) {
-         strncpy(info.storage, ua->argv[0], MAX_NAME_LENGTH);
+         bstrncpy(info.storage, ua->argv[0], MAX_NAME_LENGTH);
          break;
       }
    }
@@ -236,7 +236,7 @@ static bool check_for_new_storage(JCR *jcr, bootstrap_info &info)
          return false;
       }
       /* note the next storage name */
-      strncpy(info.storage, ua->argv[0], MAX_NAME_LENGTH);
+      bstrncpy(info.storage, ua->argv[0], MAX_NAME_LENGTH);
       Dmsg1(5, "Change storage to %s\n", info.storage);
       return true;
    }
index ceca225ee2efb80d5272b3bdbca4b1f1aca2b7e3..e5b1855496d6ee9d0162a8f630800145574d1128 100644 (file)
@@ -1994,8 +1994,8 @@ static int cloud_list_cmd(UAContext *ua, const char *cmd)
    bool first=true;
    uint32_t maxpart=0, part;
    uint64_t maxpart_size=0;
-   memset(&pr, 0, sizeof(pr));
-   memset(&mr, 0, sizeof(mr));
+   memset((void *)&pr, 0, sizeof(pr));
+   memset((void *)&mr, 0, sizeof(mr));
 
    /* Look at arguments */
    for (int i=1; i<ua->argc; i++) {
index 9fec5ed19857219d93980ffbe2e4b98f152ef504..e792b990746c6d748673ff37469bc4dde856e8ad 100644 (file)
@@ -1246,7 +1246,7 @@ void status_slots(UAContext *ua, STORE *store_r)
       }
    ua->send_msg(_("+------+----------------------+-----------+-----------------+--------------------+\n"));
 
-      memset(&mr, 0, sizeof(MEDIA_DBR));
+      memset((void *)&mr, 0, sizeof(MEDIA_DBR));
       bstrncpy(mr.VolumeName, vl->VolName, sizeof(mr.VolumeName));
 
       if (mr.VolumeName[0] && db_get_media_record(ua->jcr, ua->db, &mr)) {
index 93be8e809271022e4c1f30a952e17029e494735e..e6d98d375afae73113f86692ce14980de688bf2b 100644 (file)
@@ -808,7 +808,7 @@ static bool prune_expired_volumes(UAContext *ua)
 
    foreach_alist(val, lst) {
       nb++;
-      memset(&mr, 0, sizeof(mr));
+      memset((void *)&mr, 0, sizeof(mr));
       bstrncpy(mr.VolumeName, val, sizeof(mr.VolumeName));
       db_get_media_record(ua->jcr, ua->db, &mr);
       Mmsg(query, _("Volume \"%s\""), val);
index 1cc48c271a7916021db0d5e5ec529816654f8035..cf05a1f217181749ff6a284b2a8b15c4d10a0a5a 100644 (file)
@@ -966,8 +966,7 @@ configure_again:
       } else if (h == ini_store_name) {
          found = ini->items[i].found = get_cmd(ua, prompt.c_str());
          if (found) {
-            strncpy(ini->items[i].val.nameval, ua->cmd, MAX_NAME_LENGTH -1);
-            ini->items[i].val.nameval[MAX_NAME_LENGTH - 1] = 0;
+            bstrncpy(ini->items[i].val.nameval, ua->cmd, MAX_NAME_LENGTH);
          }
 
       } else if (h == ini_store_str) {
index eb8fd96b9fc7db138473005e88dacc56551703ae..dd22fa7d07683b6dc94d81af2b933f31b72c2b6e 100644 (file)
@@ -1180,8 +1180,7 @@ static bool init_fileset(JCR *jcr)
    if (ff->fileset) {
       return false;
    }
-   fileset = (findFILESET *)malloc(sizeof(findFILESET));
-   memset(fileset, 0, sizeof(findFILESET));
+   fileset = (findFILESET *)bmalloc(sizeof(findFILESET));
    ff->fileset = fileset;
    fileset->state = state_none;
    fileset->include_list.init(1, true);
@@ -1307,8 +1306,7 @@ findINCEXE *new_exclude(JCR *jcr)
    findFILESET *fileset = jcr->ff->fileset;
 
    /* New exclude */
-   fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-   memset(fileset->incexe, 0, sizeof(findINCEXE));
+   fileset->incexe = (findINCEXE *)bmalloc(sizeof(findINCEXE));
    fileset->incexe->opts_list.init(1, true);
    fileset->incexe->name_list.init();
    fileset->incexe->plugin_list.init();
@@ -1324,8 +1322,7 @@ findINCEXE *new_include(JCR *jcr)
    findFILESET *fileset = jcr->ff->fileset;
 
    /* New include */
-   fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-   memset(fileset->incexe, 0, sizeof(findINCEXE));
+   fileset->incexe = (findINCEXE *)bmalloc(sizeof(findINCEXE));
    fileset->incexe->opts_list.init(1, true);
    fileset->incexe->name_list.init(); /* for dlist;  was 1,true for alist */
    fileset->incexe->plugin_list.init();
@@ -1343,8 +1340,7 @@ findINCEXE *new_preinclude(JCR *jcr)
    findFILESET *fileset = jcr->ff->fileset;
 
    /* New pre-include */
-   fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-   memset(fileset->incexe, 0, sizeof(findINCEXE));
+   fileset->incexe = (findINCEXE *)bmalloc(sizeof(findINCEXE));
    fileset->incexe->opts_list.init(1, true);
    fileset->incexe->name_list.init(); /* for dlist;  was 1,true for alist */
    fileset->incexe->plugin_list.init();
@@ -1359,8 +1355,7 @@ static findFOPTS *start_options(FF_PKT *ff)
 
    if (state != state_options) {
       ff->fileset->state = state_options;
-      findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
-      memset(fo, 0, sizeof(findFOPTS));
+      findFOPTS *fo = (findFOPTS *)bmalloc(sizeof(findFOPTS));
       fo->regex.init(1, true);
       fo->regexdir.init(1, true);
       fo->regexfile.init(1, true);
@@ -1385,8 +1380,7 @@ void new_options(JCR *jcr, findINCEXE *incexe)
    if (!incexe) {
       incexe = jcr->ff->fileset->incexe;
    }
-   findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
-   memset(fo, 0, sizeof(findFOPTS));
+   findFOPTS *fo = (findFOPTS *)bmalloc(sizeof(findFOPTS));
    fo->regex.init(1, true);
    fo->regexdir.init(1, true);
    fo->regexfile.init(1, true);
index 9ed0ff2d295134c95fa060acc44e282f5c662c45..67950a7bcf65489742528d3fd321350852b791d3 100644 (file)
@@ -366,7 +366,7 @@ void do_restore(JCR *jcr)
    /* ***FIXME*** make configurable */
    crypto_digest_t signing_algorithm = have_sha2 ?
                                        CRYPTO_DIGEST_SHA256 : CRYPTO_DIGEST_SHA1;
-   memset(&rctx, 0, sizeof(rctx));
+   memset((void *)&rctx, 0, sizeof(rctx));
    rctx.jcr = jcr;
 
    /* The following variables keep track of "known unknowns" */
index da424832792b3266212af0bda1a31ac05c7ab3cd..59d393051a9846742c039aeef0335151ffe37054 100644 (file)
@@ -290,7 +290,7 @@ extern "C" HANDLE get_osfhandle(int fd);
 
 void binit(BFILE *bfd)
 {
-   memset(bfd, 0, sizeof(BFILE));
+   memset((void *)bfd, 0, sizeof(BFILE));
    bfd->fid = -1;
    bfd->mode = BF_CLOSED;
    bfd->use_backup_api = have_win32_api();
@@ -880,7 +880,7 @@ boffset_t blseek(BFILE *bfd, boffset_t offset, int whence)
 /* Unix */
 void binit(BFILE *bfd)
 {
-   memset(bfd, 0, sizeof(BFILE));
+   memset((void *)bfd, 0, sizeof(BFILE));
    bfd->fid = -1;
 }
 
index 47d78123766c3be7025026e2502e075968ccf05a..2c667051ccadb49c283150ef2300d80c01c9b351 100644 (file)
@@ -51,8 +51,8 @@ FF_PKT *init_find_files()
 {
   FF_PKT *ff;
 
+  /* bmalloc returns zeroed buffer */
   ff = (FF_PKT *)bmalloc(sizeof(FF_PKT));
-  memset(ff, 0, sizeof(FF_PKT));
 
   ff->sys_fname = get_pool_memory(PM_FNAME);
 
index 764a3e5ce5edd328d69857fb053f1fc0c7aad3e2..986047d05c16160d205dc104992768a0f66e4715 100644 (file)
@@ -86,7 +86,7 @@ static inline int LINKHASH(const struct stat &info)
 static FF_PKT *new_dir_ff_pkt(FF_PKT *ff_pkt)
 {
    FF_PKT *dir_ff_pkt = (FF_PKT *)bmalloc(sizeof(FF_PKT));
-   memcpy(dir_ff_pkt, ff_pkt, sizeof(FF_PKT));
+   memcpy((void *)dir_ff_pkt, (void *)ff_pkt, sizeof(FF_PKT));
    dir_ff_pkt->fname = bstrdup(ff_pkt->fname);
    dir_ff_pkt->link = bstrdup(ff_pkt->link);
    dir_ff_pkt->sys_fname = get_pool_memory(PM_FNAME);
index 917ebaf0fd80565c96bd3e42dc6284b6ebd4e788..0122b23e73c335043103637a949202230816a504 100644 (file)
@@ -218,6 +218,9 @@ int bmicrosleep(int32_t sec, int32_t usec)
    return stat;
 }
 
+/* allow using strncpy in this file */
+#undef strncpy
+
 /*
  * Guarantee that the string is properly terminated */
 char *bstrncpy(char *dest, const char *src, int maxlen)
@@ -1007,7 +1010,7 @@ void stack_trace()
             function = ret;
          } else {
             /* demangling failed, just pretend it's a C function with no args */
-            strncpy(function, begin, sz);
+            bstrncpy(function, begin, sz);
             strncat(function, "()", sz);
             function[sz-1] = '\0';
          }
index 29f46c34c1369baa99c0322e41bd77ee79c88bff..6711d2c2143031da7fd52d2696b44a9cf72a9b6e 100644 (file)
@@ -227,7 +227,7 @@ void htable::grow_table()
    Dmsg1(100, "Grow called old size = %d\n", buckets);
    /* Setup a bigger table */
    htable *big = (htable *)malloc(sizeof(htable));
-   memcpy(big, this, sizeof(htable));  /* start with original class data */
+   memcpy((void *)big, (void *)this, sizeof(htable));  /* start with original class data */
    big->loffset = loffset;
    big->mask = mask<<1 | 1;
    big->rshift = rshift - 1;
index f3c188f9d6fa127ecb9186f0fe907d80adf58e46..62e94f11dd949bd2069dcb618d877b536637e6dd 100644 (file)
@@ -532,7 +532,7 @@ bool ini_store_name(LEX *lc, ConfigFile *inifile, ini_items *item)
       return false;
    }
    Dmsg1(dbglevel, "ini_store_name: %s\n", lc->str);
-   strncpy(item->val.nameval, lc->str, sizeof(item->val.nameval));
+   bstrncpy(item->val.nameval, lc->str, sizeof(item->val.nameval));
    scan_to_eol(lc);
    return true;
 }
index 6728bde50ad58437467a653bbbeaeecdc9f9c105..f643a240c8ac59b1f9fe8657f024bb247f572da4 100644 (file)
@@ -274,7 +274,7 @@ void my_name_is(int argc, char *argv[], const char *name)
 #endif
       if (!respath){
          /* no resolved_path available in cargv0, so populate it */
-         strncpy(cargv0, argv[0], path_max);
+         bstrncpy(cargv0, argv[0], path_max);
       }
       /* strip trailing filename and save exepath */
       for (l=p=cargv0; *p; p++) {
@@ -789,7 +789,7 @@ static void send_to_syslog(int mode, const char *msg)
 
    while (*p && ((p2 = strchr(p, '\n')) != NULL)) {
       len = MIN((int)sizeof(buf) - 1, p2 - p + 1); /* Add 1 to keep \n */
-      strncpy(buf, p, len);
+      bstrncpy(buf, p, len);
       buf[len] = 0;
       syslog(mode, "%s", buf);
       p = p2+1;                 /* skip \n */
index 78c78efaf35c6d983693c9dee6e314dce5dbed4c..49bba00330e420aa7a10402f7e8bc0a16ec0f66c 100644 (file)
@@ -214,7 +214,7 @@ char *asciidump(const char *data, int len, char *buf, int capacity)
    char *b=buf;
    const unsigned char *p=(const unsigned char *)data;
    if (!data) {
-      strncpy(buf, "<NULL>", capacity);
+      bstrncpy(buf, "<NULL>", capacity);
       return buf;
    }
    while (len>0 && capacity>1) {
@@ -242,7 +242,7 @@ char *smartdump(const char *data, int len, char *buf, int capacity, bool *is_asc
    int c=capacity;
    const unsigned char *p=(const unsigned char *)data;
    if (!data) {
-      strncpy(buf, "<NULL>", capacity);
+      bstrncpy(buf, "<NULL>", capacity);
       return buf;
    }
    if (is_ascii != NULL) {
index df3695f2dc2c58c6b45576e628989d09ecc8285a..3de5b2e2b532f583dc74671f1a34e3ec1152be59 100644 (file)
@@ -620,7 +620,7 @@ static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
    if (strlen(rp->where) > 512) {
       printf("Restore target dir too long. Restricting to first 512 bytes.\n");
    }
-   strncpy(((struct plugin_ctx *)ctx->pContext)->where, rp->where, 512);
+   bstrncpy(((struct plugin_ctx *)ctx->pContext)->where, rp->where, 512);
    ((struct plugin_ctx *)ctx->pContext)->replace = rp->replace;
    rp->create_status = CF_EXTRACT;
    return bRC_OK;
index 0a6373a2a711ddeec776a62601e98c63c25adaaf..aac75d8b50b6f961143dcf78c2124b8206836dfc 100644 (file)
@@ -675,7 +675,7 @@ static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
    if (strlen(rp->where) > 990) {
       printf("Restore target dir too long. Restricting to first 990 bytes.\n");
    }
-   strncpy(pctx->where, rp->where, sizeof(pctx->where));
+   bstrncpy(pctx->where, rp->where, sizeof(pctx->where));
    pctx->replace = rp->replace;
    rp->create_status = CF_CORE;
    return bRC_OK;
index acfd460dc8c77ec2c229ce2c824fcdac980907e9..7286b88df6b6f9c6ae2bb8e48e0a14bce3f4fe21 100644 (file)
@@ -1065,7 +1065,7 @@ bool qstatus_cmd(JCR *jcr)
          unbash_spaces(collname);
 
       } else if (!strcmp(argk[i], "api_opts") && argv[i]) {
-         strncpy(sp.api_opts, argv[i], sizeof(sp.api_opts));
+         bstrncpy(sp.api_opts, argv[i], sizeof(sp.api_opts));
       }
    }
 
index f8240a7c252376b1ca75197a491384fde13fca28..65b4d55eb1cc5049e1d97efad6c9e6cc54c13132 100644 (file)
@@ -148,7 +148,7 @@ int main (int argc, char *const *argv)
    }
    for (i = 0; i < argc; --argc, ++argv) {
       FF_PKT ff_pkt;
-      memset(&ff_pkt, 0, sizeof(ff_pkt));
+      memset((void *)&ff_pkt, 0, sizeof(ff_pkt));
       ff_pkt.fname = ff_pkt.link = *argv;
       if (lstat(ff_pkt.fname, &ff_pkt.statp) != 0) {
          fprintf(stderr, "lstat of %s failed.\n", ff_pkt.fname);
index de3f863d4daff448752c5913a2210bb1cd318028..7cd561cf45771f9b151a7a440edd697ea21807ad 100644 (file)
@@ -378,7 +378,7 @@ static void count_files(FF_PKT *ar)
       trunc_fname++;
    }
    if (fnl > 0) {
-      strncpy(file, l, fnl);          /* copy filename */
+      bstrncpy(file, l, fnl);          /* copy filename */
       file[fnl] = 0;
    } else {
       file[0] = ' ';                  /* blank filename */
@@ -394,7 +394,7 @@ static void count_files(FF_PKT *ar)
       pnl = 255;
       trunc_path++;
    }
-   strncpy(spath, ar->fname, pnl);
+   bstrncpy(spath, ar->fname, pnl);
    spath[pnl] = 0;
    if (pnl == 0) {
       spath[0] = ' ';
@@ -419,8 +419,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
    findFILESET *fileset;
    findFOPTS *current_opts;
 
-   fileset = (findFILESET *)malloc(sizeof(findFILESET));
-   memset(fileset, 0, sizeof(findFILESET));
+   fileset = (findFILESET *)bmalloc(sizeof(findFILESET));
    ff->fileset = fileset;
 
    fileset->state = state_none;
@@ -441,8 +440,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
             ie = jcr_fileset->include_items[i];
 
             /* New include */
-            fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-            memset(fileset->incexe, 0, sizeof(findINCEXE));
+            fileset->incexe = (findINCEXE *)bmalloc(sizeof(findINCEXE));
             fileset->incexe->opts_list.init(1, true);
             fileset->incexe->name_list.init(0, 0);
             fileset->include_list.append(fileset->incexe);
@@ -450,8 +448,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
             ie = jcr_fileset->exclude_items[i];
 
             /* New exclude */
-            fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-            memset(fileset->incexe, 0, sizeof(findINCEXE));
+            fileset->incexe = (findINCEXE *)bmalloc(sizeof(findINCEXE));
             fileset->incexe->opts_list.init(1, true);
             fileset->incexe->name_list.init(0, 0);
             fileset->exclude_list.append(fileset->incexe);
@@ -460,8 +457,7 @@ static bool copy_fileset(FF_PKT *ff, JCR *jcr)
          for (j=0; j<ie->num_opts; j++) {
             FOPTS *fo = ie->opts_list[j];
 
-            current_opts = (findFOPTS *)malloc(sizeof(findFOPTS));
-            memset(current_opts, 0, sizeof(findFOPTS));
+            current_opts = (findFOPTS *)bmalloc(sizeof(findFOPTS));
             fileset->incexe->current_opts = current_opts;
             fileset->incexe->opts_list.append(current_opts);