item = cmd->items;
item->type = KDBUS_ITEM_NAME;
item->size = KDBUS_ITEM_HEADER_SIZE + strlen(name) + 1;
- strncpy(item->str, name, strlen(name));
+ strncpy(item->str, name, strlen(name) + 1);
/*
* Employ the command on the connection owner file descriptor.
std::string getDir(std::string path) {
// dirname may modify path, so we must pass a modifiable char* to it
char* modifiable_path = new char[path.size() + 1];
- strcpy(modifiable_path, path.c_str());
+ strncpy(modifiable_path, path.c_str(), path.size() + 1);
std::string ret = dirname(modifiable_path);
delete[] modifiable_path;
return ret;
cmd->cmd_info.items->size = (__u64)offsetof(struct kdbus_item, data) + (__u64)l + (__u64)1;
cmd->cmd_info.items->type = KDBUS_ITEM_NAME;
*(uint64_t*)ALIGNDN8((uintptr_t)cmd->cmd_info.items->str + l) = 0; /* trailing zero + padding */
- memcpy(cmd->cmd_info.items->str, destination, l);
+ memcpy(cmd->cmd_info.items->str, destination, l + 1);
}
r = ioctl(g_conn[bus_type].fd, KDBUS_CMD_CONN_INFO, &cmd->cmd_info);
if (r < 0) {