Ejemplo n.º 1
0
        /// <summary>
        /// Perform the additional path checks that would normally happen when creating a FileIOPermission object.
        /// </summary>
        /// <param name="fullPath">A path that has already gone through GetFullPath or Normalize</param>
        internal static void EmulateFileIOPermissionChecks(string fullPath)
        {
            // Callers should have already made checks for invalid path format via normalization. This method will only make the
            // additional checks needed to throw the same exceptions that would normally throw when using FileIOPermission.
            // These checks are done via CheckIllegalCharacters() and StringExpressionSet in AddPathList() above.

#if !PLATFORM_UNIX
            // Checking for colon / invalid characters on device paths blocks legitimate access to objects such as named pipes.
            if (!PathInternal.IsDevice(fullPath))
            {
                // GetFullPath already checks normal invalid path characters. We need to just check additional (wildcard) characters here.
                // (By calling the standard helper we can allow extended paths \\?\ through when the support is enabled.)
                if (PathInternal.HasWildCardCharacters(fullPath))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars"));
                }

                if (PathInternal.HasInvalidVolumeSeparator(fullPath))
                {
                    throw new NotSupportedException(Environment.GetResourceString("Argument_PathFormatNotSupported"));
                }
            }
#endif // !PLATFORM_UNIX
        }