Bug 14805 - OpenDir() loses the correct errno return.
Summary: OpenDir() loses the correct errno return.
Status: RESOLVED FIXED
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: 4.15.0rc2
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Jule Anger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks: 14760
  Show dependency treegraph
 
Reported: 2021-08-19 22:18 UTC by Jeremy Allison
Modified: 2021-10-05 13:25 UTC (History)
1 user (show)

See Also:


Attachments
git-am fix for 4.15.0, 4.14.next (1.23 KB, patch)
2021-08-20 15:39 UTC, Jeremy Allison
npower: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Allison 2021-08-19 22:18:59 UTC
Inside OpenDir() we have:

struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx,
                        connection_struct *conn,
                        const struct smb_filename *smb_dname,
                        const char *mask,
                        uint32_t attr)
{
        struct files_struct *fsp = NULL;
        struct smb_Dir *dir_hnd = NULL;
        NTSTATUS status;

        status = open_internal_dirfsp(conn,
                                      smb_dname,
                                      O_RDONLY,
                                      &fsp);
        if (!NT_STATUS_IS_OK(status)) {
                return NULL;
        }
        dir_hnd = OpenDir_fsp(mem_ctx, conn, fsp, mask, attr);
        if (dir_hnd == NULL) {
                return NULL;
        }

        /*
         * This overwrites the destructor set by smb_Dir_OpenDir_destructor(),
         * but smb_Dir_OpenDir_destructor() calls the OpenDir_fsp() destructor.
         */
        talloc_set_destructor(dir_hnd, smb_Dir_OpenDir_destructor);
        return dir_hnd;
}

The callers of OpenDir() then check errno if it returns NULL.

However, open_internal_dirfsp() is quite a complex beast, calling non_widelink_open and others. The NTSTATUS returned from open_internal_dirfsp() can become disconnected from errno, depending on the module stack. OpenDir_fsp() is very careful to set the correct errno on exit, OpenDir() needs to do the same.

Have patch, need bugnumber.
Comment 2 Samba QA Contact 2021-08-20 09:57:03 UTC
This bug was referenced in samba master:

72b4fe93f15e414ca3e7d7f0e77a5f0aae90556a
Comment 3 Jeremy Allison 2021-08-20 15:39:23 UTC
Created attachment 16746 [details]
git-am fix for 4.15.0, 4.14.next

Both 4.14 and 4.15 need this.
Comment 4 Jeremy Allison 2021-08-20 15:39:54 UTC
Comment on attachment 16746 [details]
git-am fix for 4.15.0, 4.14.next

Cherry-picked from master.
Comment 5 Noel Power 2021-08-20 15:47:30 UTC
Comment on attachment 16746 [details]
git-am fix for 4.15.0, 4.14.next

lgtm
Comment 6 Noel Power 2021-08-20 15:48:20 UTC
reassign to Jule for 4.14, 4.15
Comment 7 Jule Anger 2021-08-25 08:49:07 UTC
Pushed to autobuild-v4-{15,14}-test.
Comment 8 Samba QA Contact 2021-08-25 13:50:03 UTC
This bug was referenced in samba v4-15-test:

34d2bc284607ada608948bfccc7686fb14cb9c39
Comment 9 Samba QA Contact 2021-08-26 09:25:54 UTC
This bug was referenced in samba v4-15-stable (Release samba-4.15.0rc3):

34d2bc284607ada608948bfccc7686fb14cb9c39
Comment 10 Samba QA Contact 2021-08-26 16:04:02 UTC
This bug was referenced in samba v4-14-test:

4fbd8a22c3df7fe9ac4d0f17590a1b6fbdb906d3
Comment 11 Jule Anger 2021-08-27 07:36:34 UTC
Closing out bug report.

Thanks!
Comment 12 Samba QA Contact 2021-10-05 13:25:49 UTC
This bug was referenced in samba v4-14-stable (Release samba-4.14.8):

4fbd8a22c3df7fe9ac4d0f17590a1b6fbdb906d3