From 5a038f511413fdfaa26e41ceee35c1523185b071 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 17 Jul 2019 12:57:00 -0700 Subject: [PATCH] s3: smbd: Make dptr_close() safe to call with an fsp handle stored in dptr->dir_hnd. SMB1 doesn't currently do this, but subsequent changes will add handle based calls to SMB1 so dptr_close() has to be able to cleanly remove any back pointers. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- source3/smbd/dir.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index b885769fff7..541e7cfff62 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -229,6 +229,8 @@ done: void dptr_close(struct smbd_server_connection *sconn, int *key) { struct dptr_struct *dptr; + files_struct *fsp = NULL; + struct smb_Dir *dir_hnd = NULL; SMB_ASSERT(!sconn->using_smb2); @@ -242,8 +244,19 @@ void dptr_close(struct smbd_server_connection *sconn, int *key) return; } + dir_hnd = dptr->dir_hnd; + + if (dir_hnd != NULL && dir_hnd->fsp != NULL) { + SMB_ASSERT(dir_hnd->fsp->dptr->dir_hnd == dir_hnd); + fsp = dir_hnd->fsp; + } + dptr_close_internal(dptr); + if (fsp != NULL) { + fsp->dptr = NULL; + } + *key = INVALID_DPTR_KEY; }