Skip to content

ntpath.ismount() returns True for a UNC server with no share (e.g. \\server, \\?\UNC\server) #150557

@amruthamodela06

Description

@amruthamodela06

Bug report

Bug description:

On Windows, os.path.ismount() (ntpath.ismount()) returns True for UNC paths that have a server but no share component. A UNC mount point requires both a server and a share (\\server\share); a bare server name is not a mount point and should return False.

# Python 3.16.0a0 (current main, MSC v.1944 64-bit)
>>> import os.path
>>> os.path.ismount(r"\\server")        # server, no share
True
>>> os.path.ismount(r"\\?\UNC\server")  # extended UNC, server, no share
True

Genuine share roots correctly return True:

>>> os.path.ismount(r"\\server\share")
True
>>> os.path.ismount(r"\\?\UNC\server\share")
True

This is partly a regression. On 3.11:

>>> os.path.ismount(r"\\?\UNC\server")
False
>>> os.path.ismount(r"\\server")
OSError: [WinError 123] ...

So \\?\UNC\server changed from False to True. (The same change correctly fixed \\?\UNC\server\share, which was wrongly False on 3.11.)

Root cause:

Since the splitroot()-based rewrite in gh-101000, ismount does if drive and drive[0] in seps: return not rest. For an incomplete one-component UNC, splitroot(r"\\server") returns ('\\server', '', '') — the whole thing lands in drive with an empty tail — so it passes the share-root check despite there being no share.

Suggested fix:

Require both a server and a share component before treating a UNC drive as a mount root.

Split off from #139916 per @zooba's suggestion.

CPython versions tested on:

3.11, CPython main (3.16.0a0)

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions