CHAR rootpath[4];
UINT type;
- /* Copy Drive Letter, colon, and backslash to rootpath */
- bstrncpy(rootpath, fname, 3);
- rootpath[3] = '\0';
+ /* Copy Drive Letter, colon, and backslash to rootpath. bstrncpy will null-terminate the string */
+ bstrncpy(rootpath, fname, sizeof(rootpath);
type = GetDriveType(rootpath);
ok(get_user_home_directory("root", home.addr()) == 0, "get_user_home_directory()");
+ const char *p = "/@MYSQL/xxxx";
+ char type[10];
+ bstrncpy(type, p, 8);
+ ok(strcmp(type, "/@MYSQL") == 0, "bstrncpy()");
return report();
}
#endif
}
int len = strlen(type);
- t = (CUSTOM_TYPE*) malloc(sizeof(CUSTOM_TYPE)+len+1);
+ /* No need for additional byte for null terminating byte since
+ * placeholder for it is already in CUSTOM_TYPE struct
+ */
+ t = (CUSTOM_TYPE*) malloc(sizeof(CUSTOM_TYPE)+len);
bstrncpy(t->kw, type, len+1);
CUSTOM_TYPE *t2 = (CUSTOM_TYPE*) custom_type->insert(t, custom_type_insert);
if (t2 == t) {
}
while (*p && ((p2 = strchr(p, '\n')) != NULL)) {
- len = MIN((int)sizeof(buf) - 1, p2 - p + 1); /* Add 1 to keep \n */
+ len = MIN((int)sizeof(buf), p2 - p + 1); /* Add 1 to keep \n */
bstrncpy(buf, p, len);
- buf[len] = 0;
syslog(mode, "%s", buf);
p = p2+1; /* skip \n */
}
static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
{
// printf("bpipe-fd: createFile\n");
- if (strlen(rp->where) > 512) {
- printf("Restore target dir too long. Restricting to first 512 bytes.\n");
+ uint sz = sizeof(((struct plugin_ctx *)ctx->pContext)->where);
+ if (strlen(rp->where) > sz) {
+ printf("Restore target dir too long. Restricting to first %u bytes.\n", sz);
}
- bstrncpy(((struct plugin_ctx *)ctx->pContext)->where, rp->where, 512);
+ bstrncpy(((struct plugin_ctx *)ctx->pContext)->where, rp->where, sz);
((struct plugin_ctx *)ctx->pContext)->replace = rp->replace;
rp->create_status = CF_EXTRACT;
return bRC_OK;
* Pass back an authorization key for the File daemon
*/
if (jcr->sd_client) {
- bstrncpy(sd_auth_key, "xxx", 3);
+ bstrncpy(sd_auth_key, "xxx", 4); /* include \0 */
} else {
bsnprintf(seed, sizeof(seed), "%p%d", jcr, JobId);
make_session_key(sd_auth_key, seed, 1);
UINT type;
/* Copy Drive Letter, colon, and backslash to rootpath */
- bstrncpy(rootpath, fname, 3);
- rootpath[3] = '\0';
+ bstrncpy(rootpath, fname, 4);
type = GetDriveType(rootpath);