Use calloc where appropriate
authorVolker Lendecke <vl@samba.org>
Sat, 2 Nov 2019 14:25:25 +0000 (15:25 +0100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 5 Nov 2019 23:47:32 +0000 (09:47 +1000)
Saves around 250 bytes with -Oz

24 files changed:
lib/alloc.c
lib/dcerpc.c
lib/init.c
lib/krb5-wrapper.c
lib/libsmb2.c
lib/ntlmssp.c
lib/pdu.c
lib/smb2-cmd-close.c
lib/smb2-cmd-create.c
lib/smb2-cmd-echo.c
lib/smb2-cmd-flush.c
lib/smb2-cmd-ioctl.c
lib/smb2-cmd-logoff.c
lib/smb2-cmd-negotiate.c
lib/smb2-cmd-query-directory.c
lib/smb2-cmd-query-info.c
lib/smb2-cmd-read.c
lib/smb2-cmd-session-setup.c
lib/smb2-cmd-set-info.c
lib/smb2-cmd-tree-connect.c
lib/smb2-cmd-tree-disconnect.c
lib/smb2-cmd-write.c
lib/smb2-share-enum.c
lib/smb3-seal.c

index 88193d9d42896fef2cf36ec253924f83fe6d37f1..dccf6e62923c7aa094f0447d675e7db3c05f3171 100644 (file)
@@ -65,11 +65,10 @@ smb2_alloc_init(struct smb2_context *smb2, size_t size)
 
         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];
 }
@@ -82,12 +81,11 @@ smb2_alloc_data(struct smb2_context *smb2, void *memctx, size_t size)
 
         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);
index 38b6ad14c2eecb1f0ab95d73e120d572615324ad..ee907bf9d545cfbe8fdccb118780fcd579d2e70d 100644 (file)
@@ -265,12 +265,11 @@ dcerpc_create_context(struct smb2_context *smb2, const char *path,
 {
         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;
@@ -314,13 +313,12 @@ dcerpc_allocate_pdu(struct dcerpc_context *dce)
 {
         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++;
 
index 6e29775795a7d9a839594cd3c54eec9b84069ca6..a2944f90504375de7efaced3130219f575d86b2e 100644 (file)
@@ -174,12 +174,11 @@ struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
                 }
         }
 
-        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;
 
@@ -242,11 +241,10 @@ struct smb2_context *smb2_init_context(void)
 
         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");
index bc6ade5eb04bfb44ade430dc9e151f1b96b3a9e4..48ab4367f24e65d10d2a26ca88e8c74a5a0fa893 100644 (file)
@@ -164,12 +164,11 @@ krb5_negotiate_reply(struct smb2_context *smb2,
                 }
         }
 
-        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) {
index fb433c9d73e144f1ec9768617fe6253c62f84471..11bc936ac50c0ba2f0a8f80112e59c240dcbec3c 100644 (file)
@@ -264,13 +264,12 @@ decode_dirents(struct smb2_context *smb2, struct smb2dir *dir,
                         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);
 
 
@@ -440,12 +439,11 @@ smb2_opendir_async(struct smb2_context *smb2, const char *path,
                 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;
@@ -909,12 +907,11 @@ smb2_connect_share_async(struct smb2_context *smb2,
                 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);
@@ -1005,12 +1002,11 @@ smb2_open_async(struct smb2_context *smb2, const char *path, int flags,
         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;
@@ -1214,12 +1210,11 @@ smb2_pread_async(struct smb2_context *smb2, struct smb2fh *fh,
                 }
         }
 
-        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;
@@ -1306,12 +1301,11 @@ smb2_pwrite_async(struct smb2_context *smb2, struct smb2fh *fh,
                 }
         }
 
-        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;
@@ -1443,12 +1437,11 @@ smb2_unlink_internal(struct smb2_context *smb2, const char *path,
         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;
@@ -1501,12 +1494,11 @@ smb2_mkdir_async(struct smb2_context *smb2, const char *path,
         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;
@@ -1595,12 +1587,11 @@ smb2_fstat_async(struct smb2_context *smb2, struct smb2fh *fh,
         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;
@@ -1720,12 +1711,11 @@ smb2_getinfo_async(struct smb2_context *smb2, const char *path,
         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;
@@ -1867,12 +1857,11 @@ smb2_truncate_async(struct smb2_context *smb2, const char *path,
         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;
@@ -1990,12 +1979,11 @@ smb2_rename_async(struct smb2_context *smb2, const char *oldpath,
         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;
@@ -2079,12 +2067,11 @@ smb2_ftruncate_async(struct smb2_context *smb2, struct smb2fh *fh,
         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;
@@ -2176,12 +2163,11 @@ smb2_readlink_async(struct smb2_context *smb2, const char *path,
         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;
@@ -2283,12 +2269,11 @@ smb2_disconnect_share_async(struct smb2_context *smb2,
         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;
@@ -2326,12 +2311,11 @@ smb2_echo_async(struct smb2_context *smb2,
         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;
@@ -2369,11 +2353,10 @@ smb2_fh_from_file_id(struct smb2_context *smb2, smb2_file_id *fileid)
 {
         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);
 
index 92bcf167d82b2b55fed78a12e3813d05f41148ef..a793f21a01be9fe456f5e0127ab1e6c3e4963f82 100644 (file)
@@ -120,11 +120,10 @@ ntlmssp_init_context(const char *user,
 {
         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;
index 216fef67cf0918feb40854ea8b194423487e2224..70a0b6f2147ca8fcacc840f728b12536a511e131 100644 (file)
--- a/lib/pdu.c
+++ b/lib/pdu.c
@@ -72,12 +72,11 @@ smb2_allocate_pdu(struct smb2_context *smb2, enum smb2_command command,
         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;
         
index b106b4a982d169d832d1844bb45e642fdb82a6bd..03f52e2880e1a12ae3e031e1e2c4cacef74d4f79 100644 (file)
@@ -55,12 +55,11 @@ smb2_encode_close_request(struct smb2_context *smb2,
         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);
 
index 0bcc7dab0197beb318355da9a10db5fba4eb4079..da825d29c865a1ad97a538b96a5736716539555f 100644 (file)
@@ -57,12 +57,11 @@ smb2_encode_create_request(struct smb2_context *smb2,
         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);
 
index 4e27a8811d2d092ebead9f456d2c6505185bd971..fae4ffb1ea5c92f1bf76daeaf7a5cb7bc3b36011 100644 (file)
@@ -53,12 +53,11 @@ smb2_encode_echo_request(struct smb2_context *smb2,
         
         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);
 
index 1f434e298b9fe56f84683c858a64ab295ef7aba2..427ba4fac9e336ad1e75ad2a61666fa4fb2dec09 100644 (file)
@@ -55,12 +55,11 @@ smb2_encode_flush_request(struct smb2_context *smb2,
         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);
 
index 3ecce6885f1dfac659c2495f82f79810eab34eff..d216b092b50a02d5d600ba7e772a9cb0b0636c1a 100644 (file)
@@ -146,12 +146,11 @@ smb2_encode_ioctl_request(struct smb2_context *smb2,
         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);
 
index 387f7b5ec9b9d934f3403ce2f5c18cf194999d5d..890de12508fca555ac62be228981053e8b3fff54 100644 (file)
@@ -53,12 +53,11 @@ smb2_encode_logoff_request(struct smb2_context *smb2,
         
         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);
 
index c2299ee58c54b21a81ca4a9c82728013d0e5e3c3..4a7a97ce24b863dd4d92c5b7e0f57998c1c9d9b3 100644 (file)
@@ -57,12 +57,11 @@ smb2_encode_negotiate_request(struct smb2_context *smb2,
         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);
         
index f69575169f4d25ab5e3c84db5741cdc2b00f6905..c74f23c123dc3e7c79f2304ab8b0085f74fc0126 100644 (file)
@@ -102,12 +102,11 @@ smb2_encode_query_directory_request(struct smb2_context *smb2,
         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);
 
index 1b5e7fa1eb25ce0afa5ada3b920c54992d52b1fe..8ec833caa719363080f0448e04f7b541c1ccc446 100644 (file)
@@ -61,12 +61,11 @@ smb2_encode_query_info_request(struct smb2_context *smb2,
         }
 
         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);
 
index f9d684b2139f0afc96d8db25745c8e99bdb54092..0f4076ffc6be89f78932134fee89dd2a7fdf2acd 100644 (file)
@@ -55,12 +55,11 @@ smb2_encode_read_request(struct smb2_context *smb2,
         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);
 
index 586e0f642d0c444927454024e1f98ebc06f709f2..e8e290b69d40fee24195b19bdaba616dfcca780c 100644 (file)
@@ -55,13 +55,12 @@ smb2_encode_session_setup_request(struct smb2_context *smb2,
         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);
 
index cca15edf9150db54214203ed74c074afe4d3c277..ea5616a0b35e0afdd8cd3b5cc9fa28e3690f528b 100644 (file)
@@ -59,12 +59,11 @@ smb2_encode_set_info_request(struct smb2_context *smb2,
         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);
 
@@ -82,13 +81,12 @@ smb2_encode_set_info_request(struct smb2_context *smb2,
                         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);
@@ -97,13 +95,12 @@ smb2_encode_set_info_request(struct smb2_context *smb2,
                         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);
 
@@ -129,14 +126,13 @@ smb2_encode_set_info_request(struct smb2_context *smb2,
                         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);
 
index f4af13bbf4f48d5f866b356cd528dad7c013d31c..31b03b10f141e7c84544a6217ee88920f44bb918 100644 (file)
@@ -55,13 +55,12 @@ smb2_encode_tree_connect_request(struct smb2_context *smb2,
         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);
         
index 106360b4633c8591e4626e81c4f0b4513c6bf18e..b1e085a572045b3dfc265b4d711b4beafafbe0bf 100644 (file)
@@ -53,13 +53,12 @@ smb2_encode_tree_disconnect_request(struct smb2_context *smb2,
         
         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);
         
index 39bdb87ca066964d573668e21355d5391bcaff24..5bd55a8588ea26c387337f93ffd9f129e50deeee 100644 (file)
@@ -55,12 +55,11 @@ smb2_encode_write_request(struct smb2_context *smb2,
         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);
 
index a62536d703c0001ab68434fa7d99df2f98cf1372..c01da50a03158019f69d4b77b61e43a0eccb9b08 100644 (file)
@@ -158,13 +158,12 @@ smb2_share_enum_async(struct smb2_context *smb2,
                 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;
 
index d5a294afa55e91ea6a30f58352b14d9306e293f9..f1b6729db87edc557da6b2a573686ecb0c6d6239 100644 (file)
@@ -87,13 +87,12 @@ smb3_encrypt_pdu(struct smb2_context *smb2,
                         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;