From: Jeremy Allison Date: Thu, 15 Dec 2016 20:56:08 +0000 (-0800) Subject: CVE-2017-2619: s3: smbd: Move special handling of symlink errno's into a utility... X-Git-Tag: samba-4.4.12~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=299cbc73e0ef0af696c7ee7752ed787f0af7761f;p=thirdparty%2Fsamba.git CVE-2017-2619: s3: smbd: Move special handling of symlink errno's into a utility function. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12496 Signed-off-by: Jeremy Allison Reviewed-by: Uri Simchoni --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index a014b5e9974..b4b77cd0364 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -351,6 +351,31 @@ static NTSTATUS check_base_file_access(struct connection_struct *conn, access_mask); } +/**************************************************************************** + Handle differing symlink errno's +****************************************************************************/ + +static int link_errno_convert(int err) +{ +#if defined(ENOTSUP) && defined(OSF1) + /* handle special Tru64 errno */ + if (err == ENOTSUP) { + err = ELOOP; + } +#endif /* ENOTSUP */ +#ifdef EFTYPE + /* fix broken NetBSD errno */ + if (err == EFTYPE) { + err = ELOOP; + } +#endif /* EFTYPE */ + /* fix broken FreeBSD errno */ + if (err == EMLINK) { + err = ELOOP; + } + return err; +} + /**************************************************************************** fd support routines - attempt to do a dos_open. ****************************************************************************/ @@ -374,23 +399,7 @@ NTSTATUS fd_open(struct connection_struct *conn, fsp->fh->fd = SMB_VFS_OPEN(conn, smb_fname, fsp, flags, mode); if (fsp->fh->fd == -1) { - int posix_errno = errno; -#if defined(ENOTSUP) && defined(OSF1) - /* handle special Tru64 errno */ - if (errno == ENOTSUP) { - posix_errno = ELOOP; - } -#endif /* ENOTSUP */ -#ifdef EFTYPE - /* fix broken NetBSD errno */ - if (errno == EFTYPE) { - posix_errno = ELOOP; - } -#endif /* EFTYPE */ - /* fix broken FreeBSD errno */ - if (errno == EMLINK) { - posix_errno = ELOOP; - } + int posix_errno = link_errno_convert(errno); status = map_nt_error_from_unix(posix_errno); if (errno == EMFILE) { static time_t last_warned = 0L;