From: Volker Lendecke Date: Thu, 20 Oct 2022 08:10:43 +0000 (+0200) Subject: libsmb: Keep name_utf16 around in smb2cli_create() X-Git-Tag: talloc-2.4.0~510 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fbd4b27cb32f2f93793b8c6c44eb5d37034fcf8;p=thirdparty%2Fsamba.git libsmb: Keep name_utf16 around in smb2cli_create() This is needed to pass up the "unparsed" part of the smb2 symlink error response in unix charset form. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/libcli/smb/smb2cli_create.c b/libcli/smb/smb2cli_create.c index 325bc79f9cd..ca73ca6efb9 100644 --- a/libcli/smb/smb2cli_create.c +++ b/libcli/smb/smb2cli_create.c @@ -25,6 +25,8 @@ #include "smb2_create_blob.h" struct smb2cli_create_state { + uint8_t *name_utf16; + size_t name_utf16_len; uint8_t fixed[56]; uint64_t fid_persistent; @@ -57,8 +59,6 @@ struct tevent_req *smb2cli_create_send( struct tevent_req *req, *subreq; struct smb2cli_create_state *state; uint8_t *fixed; - uint8_t *name_utf16; - size_t name_utf16_len; DATA_BLOB blob; NTSTATUS status; size_t blobs_offset; @@ -67,6 +67,7 @@ struct tevent_req *smb2cli_create_send( size_t max_dyn_len; uint32_t additional_flags = 0; uint32_t clear_flags = 0; + bool ok; req = tevent_req_create(mem_ctx, &state, struct smb2cli_create_state); @@ -74,16 +75,22 @@ struct tevent_req *smb2cli_create_send( return NULL; } - if (!convert_string_talloc(state, CH_UNIX, CH_UTF16, - filename, strlen(filename), - &name_utf16, &name_utf16_len)) { + ok = convert_string_talloc( + state, + CH_UNIX, + CH_UTF16, + filename, + strlen(filename), + &state->name_utf16, + &state->name_utf16_len); + if (!ok) { tevent_req_oom(req); return tevent_req_post(req, ev); } if (strlen(filename) == 0) { - TALLOC_FREE(name_utf16); - name_utf16_len = 0; + TALLOC_FREE(state->name_utf16); + state->name_utf16_len = 0; } fixed = state->fixed; @@ -98,7 +105,7 @@ struct tevent_req *smb2cli_create_send( SIVAL(fixed, 40, create_options); SSVAL(fixed, 44, SMB2_HDR_BODY + 56); - SSVAL(fixed, 46, name_utf16_len); + SSVAL(fixed, 46, state->name_utf16_len); blob = data_blob_null; @@ -109,7 +116,7 @@ struct tevent_req *smb2cli_create_send( } } - blobs_offset = name_utf16_len; + blobs_offset = state->name_utf16_len; blobs_offset = ((blobs_offset + 3) & ~3); if (blob.length > 0) { @@ -124,9 +131,8 @@ struct tevent_req *smb2cli_create_send( return tevent_req_post(req, ev); } - if (name_utf16) { - memcpy(dyn, name_utf16, name_utf16_len); - TALLOC_FREE(name_utf16); + if (state->name_utf16 != NULL) { + memcpy(dyn, state->name_utf16, state->name_utf16_len); } if (blob.data != NULL) {