@@ -97,6 +97,18 @@ usage(char *name)
exit(1);
}
+static void *
+xmalloc0(size_t nbytes)
+{
+ void *result = calloc(1, nbytes);
+ if (result == NULL) {
+ fprintf(stderr, "%s: failed to allocate %zu bytes.\n",
+ __func__, nbytes);
+ exit(1);
+ }
+ return result;
+}
+
static void
win_to_timeval(uint64_t smb2_time, struct timeval *tv)
{
@@ -225,8 +237,7 @@ fsctlgetobjid(int f)
fstat(f, &st);
- qi = malloc(sizeof(struct smb_query_info) + 64);
- memset(qi, 0, sizeof(qi) + 64);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 64);
qi->info_type = 0x9009c;
qi->file_info_class = 0;
qi->additional_information = 0;
@@ -268,8 +279,7 @@ fileaccessinfo(int f)
fstat(f, &st);
- qi = malloc(sizeof(struct smb_query_info) + 4);
- memset(qi, 0, sizeof(qi) + 4);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 4);
qi->info_type = 0x01;
qi->file_info_class = 8;
qi->additional_information = 0;
@@ -322,8 +332,7 @@ filealigninfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 4);
- memset(qi, 0, sizeof(qi) + 4);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 4);
qi->info_type = 0x01;
qi->file_info_class = 17;
qi->additional_information = 0;
@@ -392,8 +401,7 @@ filebasicinfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 40);
- memset(qi, 0, sizeof(qi) + 40);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 40);
qi->info_type = 0x01;
qi->file_info_class = 4;
qi->additional_information = 0;
@@ -432,8 +440,7 @@ filestandardinfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 24);
- memset(qi, 0, sizeof(qi) + 24);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 24);
qi->info_type = 0x01;
qi->file_info_class = 5;
qi->additional_information = 0;
@@ -462,8 +469,7 @@ fileinternalinfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 8);
- memset(qi, 0, sizeof(qi) + 8);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 8);
qi->info_type = 0x01;
qi->file_info_class = 6;
qi->additional_information = 0;
@@ -505,8 +511,7 @@ filemodeinfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 4);
- memset(qi, 0, sizeof(qi) + 4);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 4);
qi->info_type = 0x01;
qi->file_info_class = 16;
qi->additional_information = 0;
@@ -535,8 +540,7 @@ filepositioninfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 8);
- memset(qi, 0, sizeof(qi) + 8);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 8);
qi->info_type = 0x01;
qi->file_info_class = 14;
qi->additional_information = 0;
@@ -565,8 +569,7 @@ fileeainfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 4);
- memset(qi, 0, sizeof(qi) + 4);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 4);
qi->info_type = 0x01;
qi->file_info_class = 7;
qi->additional_information = 0;
@@ -610,8 +613,7 @@ filefsfullsizeinfo(int f)
{
struct smb_query_info *qi;
- qi = malloc(sizeof(struct smb_query_info) + 32);
- memset(qi, 0, sizeof(qi) + 32);
+ qi = xmalloc0(sizeof(struct smb_query_info) + 32);
qi->info_type = 0x02;
qi->file_info_class = 7;
qi->additional_information = 0;
@@ -634,8 +636,7 @@ fileallinfo(int f)
fstat(f, &st);
- qi = malloc(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
- memset(qi, 0, sizeof(qi) + INPUT_BUFFER_LENGTH);
+ qi = xmalloc0(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
qi->info_type = 0x01;
qi->file_info_class = 18;
qi->additional_information = 0;
@@ -862,8 +863,7 @@ secdesc(int f)
fstat(f, &st);
- qi = malloc(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
- memset(qi, 0, sizeof(qi) + INPUT_BUFFER_LENGTH);
+ qi = xmalloc0(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
qi->info_type = 0x03;
qi->file_info_class = 0;
qi->additional_information = 0x00000007; /* Owner, Group, Dacl */
@@ -892,7 +892,7 @@ one_more:
memcpy(&u32, &sd[off + 4], 4);
u32 = le32toh(u32);
- printf("SID Length %d\n", u32);
+ printf("SID Length %u\n", u32);
memcpy(&u64, &sd[off + 8], 8);
win_to_timeval(le64toh(u64), &tv);
@@ -941,8 +941,7 @@ quota(int f)
char *buf;
int i;
- qi = malloc(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
- memset(qi, 0, sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
+ qi = xmalloc0(sizeof(struct smb_query_info) + INPUT_BUFFER_LENGTH);
qi->info_type = 0x04;
qi->file_info_class = 0;
qi->additional_information = 0; /* Owner, Group, Dacl */