From 4e2de3a0cd2661af2321ec3a34348fcda9283c20 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 7 Jun 2023 15:16:44 +0200 Subject: [PATCH] smbd: Simplify make_dir_struct() We don't need the talloc_strdup and thus we can return void. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/smbd/smb1_reply.c | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/source3/smbd/smb1_reply.c b/source3/smbd/smb1_reply.c index 726d788052b..96fb929cf5c 100644 --- a/source3/smbd/smb1_reply.c +++ b/source3/smbd/smb1_reply.c @@ -1087,7 +1087,7 @@ void reply_dskattr(struct smb_request *req) Make a dir struct. ****************************************************************************/ -static bool make_dir_struct(TALLOC_CTX *ctx, +static void make_dir_struct(TALLOC_CTX *ctx, char *buf, const char *mask, const char *fname, @@ -1097,24 +1097,19 @@ static bool make_dir_struct(TALLOC_CTX *ctx, bool uc) { char *p; - char *mask2 = talloc_strdup(ctx, mask); - - if (!mask2) { - return False; - } if ((mode & FILE_ATTRIBUTE_DIRECTORY) != 0) { size = 0; } memset(buf+1,' ',11); - if ((p = strchr_m(mask2,'.')) != NULL) { - *p = 0; - push_ascii(buf+1,mask2,8, 0); + if ((p = strchr_m(mask, '.')) != NULL) { + char name[p - mask + 1]; + strlcpy(name, mask, sizeof(name)); + push_ascii(buf + 1, name, 8, 0); push_ascii(buf+9,p+1,3, 0); - *p = '.'; } else { - push_ascii(buf+1,mask2,11, 0); + push_ascii(buf + 1, mask, 11, 0); } memset(buf+21,'\0',DIR_STRUCT_SIZE-21); @@ -1126,7 +1121,6 @@ static bool make_dir_struct(TALLOC_CTX *ctx, Strange, but verified on W2K3. Needed for OS/2. JRA. */ push_ascii(buf+30,fname,12, uc ? STR_UPPER : 0); DEBUG(8,("put name [%s] from [%s] into dir struct\n",buf+30, fname)); - return True; } /**************************************************************************** @@ -1338,11 +1332,14 @@ void reply_search(struct smb_request *req) if ((dirtype&0x1F) == FILE_ATTRIBUTE_VOLUME) { char buf[DIR_STRUCT_SIZE]; memcpy(buf,status,21); - if (!make_dir_struct(ctx,buf,"???????????",volume_label(ctx, SNUM(conn)), - 0,FILE_ATTRIBUTE_VOLUME,0,!allow_long_path_components)) { - reply_nterror(req, NT_STATUS_NO_MEMORY); - goto out; - } + make_dir_struct(ctx, + buf, + "???????????", + volume_label(ctx, SNUM(conn)), + 0, + FILE_ATTRIBUTE_VOLUME, + 0, + !allow_long_path_components); dptr_fill(sconn, buf+12,dptr_num); if (dptr_zero(buf+12) && (status_len==0)) { numentries = 1; @@ -1385,17 +1382,15 @@ void reply_search(struct smb_request *req) if (!finished) { char buf[DIR_STRUCT_SIZE]; memcpy(buf,status,21); - if (!make_dir_struct(ctx, - buf, - mask, - fname, - size, - mode, - convert_timespec_to_time_t(date), - !allow_long_path_components)) { - reply_nterror(req, NT_STATUS_NO_MEMORY); - goto out; - } + make_dir_struct( + ctx, + buf, + mask, + fname, + size, + mode, + convert_timespec_to_time_t(date), + !allow_long_path_components); if (!dptr_fill(sconn, buf+12,dptr_num)) { break; } -- 2.11.4.GIT