s3: smbd: Inside filename_convert_dirfsp_nosymlink() ensure the returned smb_fname...
authorJeremy Allison <jra@samba.org>
Tue, 26 Jul 2022 21:34:27 +0000 (14:34 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 27 Jul 2022 16:51:34 +0000 (16:51 +0000)
commit22fae651656eb4e151d75b0464ef549e4af235f7
tree7d7e6c3bb6c1b3cc49130a80f2efdce7ccdd352f
parent31479d7781d3e566d9f6258016a13f349fe05389
s3: smbd: Inside filename_convert_dirfsp_nosymlink() ensure the returned smb_fname is always allocated off mem_ctx.

Without this, if we just return smb_fname_rel->fsp->fsp_name as the smb_fname
then we return something allocated off fsp (which itself is allocated off
the conn struct), not the passed in talloc_ctx.

Do this for both non-stream and stream returns.

This matters for two reasons.

1). If we error out after calling filename_convert_dirfsp()
but before getting to the code inside create_file_unixpath()
that takes ownership of the passed in smb_fname->fsp we will
leak the fsp as the destructor for smb_fname that closes the
fsp will never fire on return to the client, as smb_fname is
owned by smb_fname->fsp, not the talloc_tos() context.

2). Some uses of filename_convert() expect to be able
to TALLOC_FREE the returned smb_fname once they've successfully
called SMB_VFS_CREATE_FILE() as they consider the passed in smb_fname
no longer used. It would be nice to be able to just change
filename_convert() -> filename_convert_dirfsp() without
having to change the lifetime handling of smb_fname.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/smbd/filename.c