size += offsetof(struct smb2_alloc_header, buf);
- ptr = malloc(size);
+ ptr = calloc(size, 1);
if (ptr == NULL) {
return NULL;
}
- memset(ptr, 0, size);
return &ptr->buf[0];
}
size += offsetof(struct smb2_alloc_entry, buf);
- ptr = malloc(size);
+ ptr = calloc(size, 1);
if (ptr == NULL) {
smb2_set_error(smb2, "Failed to alloc %zu bytes", size);
return NULL;
}
- memset(ptr, 0, size);
#ifndef _MSC_VER
hdr = container_of(memctx, struct smb2_alloc_header, buf);
{
struct dcerpc_context *ctx;
- ctx = malloc(sizeof(struct dcerpc_context));
+ ctx = calloc(1, sizeof(struct dcerpc_context));
if (ctx == NULL) {
smb2_set_error(smb2, "Failed to allcoate dcercp context.");
return NULL;
}
- memset(ctx, 0, sizeof(struct dcerpc_context));
ctx->smb2 = smb2;
ctx->call_id = 2;
{
struct dcerpc_pdu *pdu;
- pdu = malloc(sizeof(struct dcerpc_pdu));
+ pdu = calloc(1, sizeof(struct dcerpc_pdu));
if (pdu == NULL) {
smb2_set_error(dce->smb2, "Failed to allocate DCERPC PDU");
return NULL;
}
- memset(pdu, 0, sizeof(struct dcerpc_pdu));
pdu->dce = dce;
pdu->hdr.call_id = dce->call_id++;
}
}
- u = malloc(sizeof(struct smb2_url));
+ u = calloc(1, sizeof(struct smb2_url));
if (u == NULL) {
smb2_set_error(smb2, "Failed to allocate smb2_url");
return NULL;
}
- memset(u, 0, sizeof(struct smb2_url));
ptr = str;
srandom(time(NULL) | getpid() | ctr++);
- smb2 = malloc(sizeof(struct smb2_context));
+ smb2 = calloc(1, sizeof(struct smb2_context));
if (smb2 == NULL) {
return NULL;
}
- memset(smb2, 0, sizeof(struct smb2_context));
ret = getlogin_r(buf, sizeof(buf));
smb2_set_user(smb2, ret == 0 ? buf : "Guest");
}
}
- auth_data = malloc(sizeof(struct private_auth_data));
+ auth_data = calloc(1, sizeof(struct private_auth_data));
if (auth_data == NULL) {
smb2_set_error(smb2, "Failed to allocate private_auth_data");
return NULL;
}
- memset(auth_data, 0, sizeof(struct private_auth_data));
auth_data->context = GSS_C_NO_CONTEXT;
if (asprintf(&auth_data->g_server, "cifs@%s", server) < 0) {
return -1;
}
- ent = malloc(sizeof(struct smb2_dirent_internal));
+ ent = calloc(1, sizeof(struct smb2_dirent_internal));
if (ent == NULL) {
smb2_set_error(smb2, "Failed to allocate "
"dirent_internal");
return -1;
}
- memset(ent, 0, sizeof(struct smb2_dirent_internal));
SMB2_LIST_ADD(&dir->entries, ent);
path = "";
}
- dir = malloc(sizeof(struct smb2dir));
+ dir = calloc(1, sizeof(struct smb2dir));
if (dir == NULL) {
smb2_set_error(smb2, "Failed to allocate smb2dir.");
return -1;
}
- memset(dir, 0, sizeof(struct smb2dir));
SMB2_LIST_ADD(&smb2->dirs, dir);
dir->cb = cb;
dir->cb_data = cb_data;
smb2_set_user(smb2, user);
}
- c_data = malloc(sizeof(struct connect_data));
+ c_data = calloc(1, sizeof(struct connect_data));
if (c_data == NULL) {
smb2_set_error(smb2, "Failed to allocate connect_data");
return -ENOMEM;
}
- memset(c_data, 0, sizeof(struct connect_data));
c_data->server = strdup(smb2->server);
if (c_data->server == NULL) {
free_c_data(smb2, c_data);
uint32_t create_options = 0;
uint32_t file_attributes = 0;
- fh = malloc(sizeof(struct smb2fh));
+ fh = calloc(1, sizeof(struct smb2fh));
if (fh == NULL) {
smb2_set_error(smb2, "Failed to allocate smbfh");
return -ENOMEM;
}
- memset(fh, 0, sizeof(struct smb2fh));
SMB2_LIST_ADD(&smb2->fhs, fh);
fh->cb = cb;
}
}
- rd = malloc(sizeof(struct rw_data));
+ rd = calloc(1, sizeof(struct rw_data));
if (rd == NULL) {
smb2_set_error(smb2, "Failed to allocate rw_data");
return -ENOMEM;
}
- memset(rd, 0, sizeof(struct rw_data));
rd->cb = cb;
rd->cb_data = cb_data;
}
}
- rd = malloc(sizeof(struct rw_data));
+ rd = calloc(1, sizeof(struct rw_data));
if (rd == NULL) {
smb2_set_error(smb2, "Failed to allocate rw_data");
return -ENOMEM;
}
- memset(rd, 0, sizeof(struct rw_data));
rd->cb = cb;
rd->cb_data = cb_data;
struct smb2_create_request req;
struct smb2_pdu *pdu;
- create_data = malloc(sizeof(struct create_cb_data));
+ create_data = calloc(1, sizeof(struct create_cb_data));
if (create_data == NULL) {
smb2_set_error(smb2, "Failed to allocate create_data");
return -ENOMEM;
}
- memset(create_data, 0, sizeof(struct create_cb_data));
create_data->cb = cb;
create_data->cb_data = cb_data;
struct smb2_create_request req;
struct smb2_pdu *pdu;
- create_data = malloc(sizeof(struct create_cb_data));
+ create_data = calloc(1, sizeof(struct create_cb_data));
if (create_data == NULL) {
smb2_set_error(smb2, "Failed to allocate create_data");
return -ENOMEM;
}
- memset(create_data, 0, sizeof(struct create_cb_data));
create_data->cb = cb;
create_data->cb_data = cb_data;
struct smb2_query_info_request req;
struct smb2_pdu *pdu;
- stat_data = malloc(sizeof(struct stat_cb_data));
+ stat_data = calloc(1, sizeof(struct stat_cb_data));
if (stat_data == NULL) {
smb2_set_error(smb2, "Failed to allocate stat_data");
return -ENOMEM;
}
- memset(stat_data, 0, sizeof(struct stat_cb_data));
stat_data->cb = cb;
stat_data->cb_data = cb_data;
struct smb2_close_request cl_req;
struct smb2_pdu *pdu, *next_pdu;
- stat_data = malloc(sizeof(struct stat_cb_data));
+ stat_data = calloc(1, sizeof(struct stat_cb_data));
if (stat_data == NULL) {
smb2_set_error(smb2, "Failed to allocate create_data");
return -1;
}
- memset(stat_data, 0, sizeof(struct stat_cb_data));
stat_data->cb = cb;
stat_data->cb_data = cb_data;
struct smb2_pdu *pdu, *next_pdu;
struct smb2_file_end_of_file_info eofi;
- trunc_data = malloc(sizeof(struct trunc_cb_data));
+ trunc_data = calloc(1, sizeof(struct trunc_cb_data));
if (trunc_data == NULL) {
smb2_set_error(smb2, "Failed to allocate trunc_data");
return -1;
}
- memset(trunc_data, 0, sizeof(struct trunc_cb_data));
trunc_data->cb = cb;
trunc_data->cb_data = cb_data;
struct smb2_pdu *pdu, *next_pdu;
struct smb2_file_rename_info rn_info;
- rename_data = malloc(sizeof(struct rename_cb_data));
+ rename_data = calloc(1, sizeof(struct rename_cb_data));
if (rename_data == NULL) {
smb2_set_error(smb2, "Failed to allocate rename_data");
return -1;
}
- memset(rename_data, 0, sizeof(struct rename_cb_data));
rename_data->cb = cb;
rename_data->cb_data = cb_data;
struct smb2_file_end_of_file_info eofi;
struct smb2_pdu *pdu;
- create_data = malloc(sizeof(struct create_cb_data));
+ create_data = calloc(1, sizeof(struct create_cb_data));
if (create_data == NULL) {
smb2_set_error(smb2, "Failed to allocate create_data");
return -ENOMEM;
}
- memset(create_data, 0, sizeof(struct create_cb_data));
create_data->cb = cb;
create_data->cb_data = cb_data;
struct smb2_close_request cl_req;
struct smb2_pdu *pdu, *next_pdu;
- readlink_data = malloc(sizeof(struct readlink_cb_data));
+ readlink_data = calloc(1, sizeof(struct readlink_cb_data));
if (readlink_data == NULL) {
smb2_set_error(smb2, "Failed to allocate readlink_data");
return -1;
}
- memset(readlink_data, 0, sizeof(struct readlink_cb_data));
readlink_data->cb = cb;
readlink_data->cb_data = cb_data;
struct disconnect_data *dc_data;
struct smb2_pdu *pdu;
- dc_data = malloc(sizeof(struct disconnect_data));
+ dc_data = calloc(1, sizeof(struct disconnect_data));
if (dc_data == NULL) {
smb2_set_error(smb2, "Failed to allocate disconnect_data");
return -ENOMEM;
}
- memset(dc_data, 0, sizeof(struct disconnect_data));
dc_data->cb = cb;
dc_data->cb_data = cb_data;
struct echo_data *echo_data;
struct smb2_pdu *pdu;
- echo_data = malloc(sizeof(struct echo_data));
+ echo_data = calloc(1, sizeof(struct echo_data));
if (echo_data == NULL) {
smb2_set_error(smb2, "Failed to allocate echo_data");
return -ENOMEM;
}
- memset(echo_data, 0, sizeof(struct echo_data));
echo_data->cb = cb;
echo_data->cb_data = cb_data;
{
struct smb2fh *fh;
- fh = malloc(sizeof(struct smb2fh));
+ fh = calloc(1, sizeof(struct smb2fh));
if (fh == NULL) {
return NULL;
}
- memset(fh, 0, sizeof(struct smb2fh));
memcpy(fh->file_id, fileid, SMB2_FD_SIZE);
SMB2_LIST_ADD(&smb2->fhs, fh);
{
struct auth_data *auth_data = NULL;
- auth_data = malloc(sizeof(struct auth_data));
+ auth_data = calloc(1, sizeof(struct auth_data));
if (auth_data == NULL) {
return NULL;
}
- memset(auth_data, 0, sizeof(struct auth_data));
auth_data->user = user;
auth_data->password = password;
struct smb2_header *hdr;
char magic[4] = {0xFE, 'S', 'M', 'B'};
- pdu = malloc(sizeof(struct smb2_pdu));
+ pdu = calloc(1, sizeof(struct smb2_pdu));
if (pdu == NULL) {
smb2_set_error(smb2, "Failed to allocate pdu");
return NULL;
}
- memset(pdu, 0, sizeof(struct smb2_pdu));
hdr = &pdu->header;
struct smb2_iovec *iov;
len = SMB2_CLOSE_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate close buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_CREATE_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate create buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
len = 4;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate echo buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_FLUSH_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate flush buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_IOCTL_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate query buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
len = 4;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate logoff buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
len = SMB2_NEGOTIATE_REQUEST_SIZE +
req->dialect_count * sizeof(uint16_t);
len = PAD_TO_32BIT(len);
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate negotiate buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_QUERY_DIRECTORY_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate query buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
}
len = SMB2_QUERY_INFO_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate query buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_READ_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate read buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_SESSION_SETUP_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate session "
"setup buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_file_rename_info *rni;
len = SMB2_SET_INFO_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate set info buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
len = 40;
smb2_set_uint32(iov, 4, len); /* buffer length */
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate set "
"info data buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len,
free);
smb2_encode_file_basic_info(smb2, req->input_data, iov);
len = 8;
smb2_set_uint32(iov, 4, len); /* buffer length */
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate set "
"info data buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len,
free);
len = 20 + name->len * 2;
smb2_set_uint32(iov, 4, len); /* buffer length */
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate set "
"info data buffer");
free(name);
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len,
free);
struct smb2_iovec *iov;
len = SMB2_TREE_CONNECT_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate tree connect setup "
"buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
len = 4;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate tree disconnect "
"buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
struct smb2_iovec *iov;
len = SMB2_WRITE_REQUEST_SIZE & 0xfffffffe;
- buf = malloc(len);
+ buf = calloc(len, sizeof(uint8_t));
if (buf == NULL) {
smb2_set_error(smb2, "Failed to allocate write buffer");
return -1;
}
- memset(buf, 0, len);
iov = smb2_add_iovector(smb2, &pdu->out, buf, len, free);
return -ENOMEM;
}
- nse = malloc(sizeof(struct smb2nse));
+ nse = calloc(1, sizeof(struct smb2nse));
if (nse == NULL) {
smb2_set_error(smb2, "Failed to allocate nse");
dcerpc_destroy_context(dce);
return -ENOMEM;
}
- memset(nse, 0, sizeof(struct smb2nse));
nse->cb = cb;
nse->cb_data = cb_data;
spl += tmp_pdu->out.iov[i].len;
}
}
- pdu->crypt = malloc(spl);
+ pdu->crypt = calloc(spl, sizeof(uint8_t));
if (pdu->crypt == NULL) {
pdu->seal = 0;
return -1;
}
- memset(pdu->crypt, 0, spl);
memcpy(&pdu->crypt[0], xfer, 4);
for (i = 20; i < 31; i++) {
pdu->crypt[i] = random()&0xff;