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
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
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();
}
exit(0);
}
- memset(&jcr, 0, sizeof(jcr));
+ memset((void *)&jcr, 0, sizeof(jcr));
(void)WSA_Init(); /* Initialize Windows sockets */
/* 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);
}
}
}
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) {
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) {
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;
}
}
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;
}
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++) {
}
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)) {
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);
} 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) {
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);
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();
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();
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();
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);
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);
/* ***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" */
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();
/* Unix */
void binit(BFILE *bfd)
{
- memset(bfd, 0, sizeof(BFILE));
+ memset((void *)bfd, 0, sizeof(BFILE));
bfd->fid = -1;
}
{
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);
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);
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)
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';
}
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;
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;
}
#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++) {
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 */
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) {
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) {
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;
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;
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));
}
}
}
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);
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 */
pnl = 255;
trunc_path++;
}
- strncpy(spath, ar->fname, pnl);
+ bstrncpy(spath, ar->fname, pnl);
spath[pnl] = 0;
if (pnl == 0) {
spath[0] = ' ';
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;
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);
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);
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);