summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Security/Util/StringExpressionSet.cs
blob: 19937f5ae629a829fe8a7ed0216318625b6cfaa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Security.Util {    
    using System.Text;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Globalization;
    using System.Runtime.Versioning;
    using System.IO;
    using System.Diagnostics.Contracts;

    [Serializable]
    internal class StringExpressionSet
    {
        // This field, as well as the expressions fields below are critical since they may contain
        // canonicalized full path data potentially built out of relative data passed as input to the
        // StringExpressionSet.  Full trust code using the string expression set needs to ensure that before
        // exposing this data out to partial trust, they protect against this.  Possibilities include:
        //
        //  1. Using the throwOnRelative flag
        //  2. Ensuring that the partial trust code has permission to see full path data
        //  3. Not using this set for paths (eg EnvironmentStringExpressionSet)
        //
        [SecurityCritical]
        protected ArrayList m_list;
        protected bool m_ignoreCase;
        [SecurityCritical]
        protected String m_expressions;
        [SecurityCritical]
        protected String[] m_expressionsArray;

        protected bool m_throwOnRelative;
        
        protected static readonly char[] m_separators = { ';' };
        protected static readonly char[] m_trimChars = { ' ' };
#if !PLATFORM_UNIX
        protected static readonly char m_directorySeparator = '\\';
        protected static readonly char m_alternateDirectorySeparator = '/';
#else
        protected static readonly char m_directorySeparator = '/';
        protected static readonly char m_alternateDirectorySeparator = '\\';
#endif // !PLATFORM_UNIX
        
        public StringExpressionSet()
            : this( true, null, false )
        {
        }
        
        public StringExpressionSet( String str )
            : this( true, str, false )
        {
        }
        
        public StringExpressionSet( bool ignoreCase, bool throwOnRelative )
            : this( ignoreCase, null, throwOnRelative )
        {
        }
        
        [System.Security.SecuritySafeCritical]  // auto-generated
        public StringExpressionSet( bool ignoreCase, String str, bool throwOnRelative )
        {
            m_list = null;
            m_ignoreCase = ignoreCase;
            m_throwOnRelative = throwOnRelative;
            if (str == null)
                m_expressions = null;
            else
            AddExpressions( str );
        }

        protected virtual StringExpressionSet CreateNewEmpty()
        {
            return new StringExpressionSet();
        }
        
        [SecuritySafeCritical]
        public virtual StringExpressionSet Copy()
        {
            // SafeCritical: just copying this value around, not leaking it

            StringExpressionSet copy = CreateNewEmpty();
            if (this.m_list != null)
                copy.m_list = new ArrayList(this.m_list);

            copy.m_expressions = this.m_expressions;
            copy.m_ignoreCase = this.m_ignoreCase;
            copy.m_throwOnRelative = this.m_throwOnRelative;
            return copy;
        }
        
        public void SetThrowOnRelative( bool throwOnRelative )
        {
            this.m_throwOnRelative = throwOnRelative;
        }

        private static String StaticProcessWholeString( String str )
        {
            return str.Replace( m_alternateDirectorySeparator, m_directorySeparator );
        }

        private static String StaticProcessSingleString( String str )
        {
            return str.Trim( m_trimChars );
        }

        protected virtual String ProcessWholeString( String str )
        {
            return StaticProcessWholeString(str);
        }

        protected virtual String ProcessSingleString( String str )
        {
            return StaticProcessSingleString(str);
        }
        
        [System.Security.SecurityCritical]  // auto-generated
        public void AddExpressions( String str )
        {
            if (str == null)
                throw new ArgumentNullException( "str" );
            Contract.EndContractBlock();
            if (str.Length == 0)
                return;

            str = ProcessWholeString( str );

            if (m_expressions == null)
                m_expressions = str;
            else
                m_expressions = m_expressions + m_separators[0] + str;

            m_expressionsArray = null;

            // We have to parse the string and compute the list here.
            // The logic in this class tries to delay this parsing but
            // since operations like IsSubsetOf are called during 
            // demand evaluation, it is not safe to delay this step
            // as that would cause concurring threads to update the object
            // at the same time. The CheckList operation should ideally be
            // removed from this class, but for the sake of keeping the 
            // changes to a minimum here, we simply make sure m_list 
            // cannot be null by parsing m_expressions eagerly.

            String[] arystr = Split( str );

            if (m_list == null)
                m_list = new ArrayList();

            for (int index = 0; index < arystr.Length; ++index)
            {
                if (arystr[index] != null && !arystr[index].Equals( "" ))
                {
                    String temp = ProcessSingleString( arystr[index] );
                    int indexOfNull = temp.IndexOf( '\0' );

                    if (indexOfNull != -1)
                        temp = temp.Substring( 0, indexOfNull );

                    if (temp != null && !temp.Equals( "" ))
                    {
                        if (m_throwOnRelative)
                        {
                            if (Path.IsRelative(temp))
                            {
                                throw new ArgumentException( Environment.GetResourceString( "Argument_AbsolutePathRequired" ) );
                            }

                            temp = CanonicalizePath( temp );
                        }

                        m_list.Add( temp );
                    }
                }
            }

            Reduce();
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void AddExpressions( String[] str, bool checkForDuplicates, bool needFullPath )
        {
            AddExpressions(CreateListFromExpressions(str, needFullPath), checkForDuplicates);
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void AddExpressions( ArrayList exprArrayList, bool checkForDuplicates)
        {
            Contract.Assert( m_throwOnRelative, "This should only be called when throw on relative is set" );

            m_expressionsArray = null;
            m_expressions = null;

            if (m_list != null)
                m_list.AddRange(exprArrayList);
            else
                m_list = new ArrayList(exprArrayList);

            if (checkForDuplicates)
                Reduce();
        }


        [System.Security.SecurityCritical]  // auto-generated
        internal static ArrayList CreateListFromExpressions(String[] str, bool needFullPath)
        {
            if (str == null)
            {
                throw new ArgumentNullException( "str" );
            }
            Contract.EndContractBlock();
            ArrayList retArrayList = new ArrayList();
            for (int index = 0; index < str.Length; ++index)
            {
                if (str[index] == null)
                    throw new ArgumentNullException( "str" );

                // Replace alternate directory separators
                String oneString = StaticProcessWholeString( str[index] );

                if (oneString != null && oneString.Length != 0)
                {
                    // Trim leading and trailing spaces
                    String temp = StaticProcessSingleString( oneString);

                    int indexOfNull = temp.IndexOf( '\0' );

                    if (indexOfNull != -1)
                        temp = temp.Substring( 0, indexOfNull );

                    if (temp != null && temp.Length != 0)
                    {
                        if (PathInternal.IsPartiallyQualified(temp))
                        {
                            throw new ArgumentException(Environment.GetResourceString( "Argument_AbsolutePathRequired" ) );
                        }

                        temp = CanonicalizePath( temp, needFullPath );

                        retArrayList.Add( temp );
                    }
                }
            }

            return retArrayList;
        }
        
        [System.Security.SecurityCritical]  // auto-generated
        protected void CheckList()
        {
            if (m_list == null && m_expressions != null)
            {
                CreateList();
            }
        }
        
        protected String[] Split( String expressions )
        {
            if (m_throwOnRelative)
            {
                List<String> tempList = new List<String>();

                String[] quoteSplit = expressions.Split( '\"' );

                for (int i = 0; i < quoteSplit.Length; ++i)
                {
                    if (i % 2 == 0)
                    {
                        String[] semiSplit = quoteSplit[i].Split( ';' );

                        for (int j = 0; j < semiSplit.Length; ++j)
                        {
                            if (semiSplit[j] != null && !semiSplit[j].Equals( "" ))
                                tempList.Add( semiSplit[j] );
                        }
                    }
                    else
                    {
                        tempList.Add( quoteSplit[i] );
                    }
                }

                String[] finalArray = new String[tempList.Count];

                IEnumerator enumerator = tempList.GetEnumerator();

                int index = 0;
                while (enumerator.MoveNext())
                {
                    finalArray[index++] = (String)enumerator.Current;
                }

                return finalArray;
            }
            else
            {
                return expressions.Split( m_separators );
            }
        }

        
        [System.Security.SecurityCritical]  // auto-generated
        protected void CreateList()
        {
            String[] expressionsArray = Split( m_expressions );

            m_list = new ArrayList();
            
            for (int index = 0; index < expressionsArray.Length; ++index)
            {
                if (expressionsArray[index] != null && !expressionsArray[index].Equals( "" ))
                {
                    String temp = ProcessSingleString( expressionsArray[index] );

                    int indexOfNull = temp.IndexOf( '\0' );

                    if (indexOfNull != -1)
                        temp = temp.Substring( 0, indexOfNull );

                    if (temp != null && !temp.Equals( "" ))
                    {
                        if (m_throwOnRelative)
                        {
                            if (Path.IsRelative(temp))
                            {
                                throw new ArgumentException( Environment.GetResourceString( "Argument_AbsolutePathRequired" ) );
                            }

                            temp = CanonicalizePath( temp );
                        }
                        
                        m_list.Add( temp );
                    }
                }
            }
        }
        
        [SecuritySafeCritical]
        public bool IsEmpty()
        {
            // SafeCritical: we're just showing that the expressions are empty, the sensitive portion is their
            // contents - not the existence of the contents
            if (m_list == null)
            {
                return m_expressions == null;
            }
            else
            {
                return m_list.Count == 0;
            }
        }
        
        [System.Security.SecurityCritical]  // auto-generated
        public bool IsSubsetOf( StringExpressionSet ses )
        {
            if (this.IsEmpty())
                return true;
            
            if (ses == null || ses.IsEmpty())
                return false;
            
            CheckList();
            ses.CheckList();
            
            for (int index = 0; index < this.m_list.Count; ++index)
            {
                if (!StringSubsetStringExpression( (String)this.m_list[index], ses, m_ignoreCase ))
                {
                    return false;
                }
            }
            return true;
        }
        
        [System.Security.SecurityCritical]  // auto-generated
        public bool IsSubsetOfPathDiscovery( StringExpressionSet ses )
        {
            if (this.IsEmpty())
                return true;
            
            if (ses == null || ses.IsEmpty())
                return false;
            
            CheckList();
            ses.CheckList();
            
            for (int index = 0; index < this.m_list.Count; ++index)
            {
                if (!StringSubsetStringExpressionPathDiscovery( (String)this.m_list[index], ses, m_ignoreCase ))
                {
                    return false;
                }
            }
            return true;
        }

        
        [System.Security.SecurityCritical]  // auto-generated
        public StringExpressionSet Union( StringExpressionSet ses )
        {
            // If either set is empty, the union represents a copy of the other.
            
            if (ses == null || ses.IsEmpty())
                return this.Copy();
    
            if (this.IsEmpty())
                return ses.Copy();
            
            CheckList();
            ses.CheckList();
            
            // Perform the union
            // note: insert smaller set into bigger set to reduce needed comparisons
            
            StringExpressionSet bigger = ses.m_list.Count > this.m_list.Count ? ses : this;
            StringExpressionSet smaller = ses.m_list.Count <= this.m_list.Count ? ses : this;
    
            StringExpressionSet unionSet = bigger.Copy();
            
            unionSet.Reduce();
            
            for (int index = 0; index < smaller.m_list.Count; ++index)
            {
                unionSet.AddSingleExpressionNoDuplicates( (String)smaller.m_list[index] );
            }
            
            unionSet.GenerateString();
            
            return unionSet;
        }
            
        
        [System.Security.SecurityCritical]  // auto-generated
        public StringExpressionSet Intersect( StringExpressionSet ses )
        {
            // If either set is empty, the intersection is empty
            
            if (this.IsEmpty() || ses == null || ses.IsEmpty())
                return CreateNewEmpty();
            
            CheckList();
            ses.CheckList();
            
            // Do the intersection for real
            
            StringExpressionSet intersectSet = CreateNewEmpty();
            
            for (int this_index = 0; this_index < this.m_list.Count; ++this_index)
            {
                for (int ses_index = 0; ses_index < ses.m_list.Count; ++ses_index)
                {
                    if (StringSubsetString( (String)this.m_list[this_index], (String)ses.m_list[ses_index], m_ignoreCase ))
                    {
                        if (intersectSet.m_list == null)
                        {
                            intersectSet.m_list = new ArrayList();
                        }
                        intersectSet.AddSingleExpressionNoDuplicates( (String)this.m_list[this_index] );
                    }
                    else if (StringSubsetString( (String)ses.m_list[ses_index], (String)this.m_list[this_index], m_ignoreCase ))
                    {
                        if (intersectSet.m_list == null)
                        {
                            intersectSet.m_list = new ArrayList();
                        }
                        intersectSet.AddSingleExpressionNoDuplicates( (String)ses.m_list[ses_index] );
                    }
                }
            }
            
            intersectSet.GenerateString();
            
            return intersectSet;
        }
        
        [SecuritySafeCritical]
        protected void GenerateString()
        {
            // SafeCritical - moves critical data around, but doesn't expose it out
            if (m_list != null)
            {
                StringBuilder sb = new StringBuilder();
            
                IEnumerator enumerator = this.m_list.GetEnumerator();
                bool first = true;
            
                while (enumerator.MoveNext())
                {
                    if (!first)
                        sb.Append( m_separators[0] );
                    else
                        first = false;
                            
                    String currentString = (String)enumerator.Current;
                    if (currentString != null)
                    {
                        int indexOfSeparator = currentString.IndexOf( m_separators[0] );

                        if (indexOfSeparator != -1)
                            sb.Append( '\"' );

                        sb.Append( currentString );

                        if (indexOfSeparator != -1)
                            sb.Append( '\"' );
                    }
                }
            
                m_expressions = sb.ToString();
            }
            else
            {
                m_expressions = null;
            }
        }            
        
        // We don't override ToString since that API must be either transparent or safe citical.  If the
        // expressions contain paths that were canonicalized and expanded from the input that would cause
        // information disclosure, so we instead only expose this out to trusted code that can ensure they
        // either don't leak the information or required full path information.
        [SecurityCritical]
        public string UnsafeToString()
        {
            CheckList();
        
            Reduce();
        
            GenerateString();
                            
            return m_expressions;
        }

        [SecurityCritical]
        public String[] UnsafeToStringArray()
        {
            if (m_expressionsArray == null && m_list != null)
            {
                m_expressionsArray = (String[])m_list.ToArray(typeof(String));
            }

            return m_expressionsArray;
        }
                
        
        //-------------------------------
        // protected static helper functions
        //-------------------------------
        
        [SecurityCritical]
        private bool StringSubsetStringExpression( String left, StringExpressionSet right, bool ignoreCase )
        {
            for (int index = 0; index < right.m_list.Count; ++index)
            {
                if (StringSubsetString( left, (String)right.m_list[index], ignoreCase ))
                {
                    return true;
                }
            }
            return false;
        }
        
        [SecurityCritical]
        private static bool StringSubsetStringExpressionPathDiscovery( String left, StringExpressionSet right, bool ignoreCase )
        {
            for (int index = 0; index < right.m_list.Count; ++index)
            {
                if (StringSubsetStringPathDiscovery( left, (String)right.m_list[index], ignoreCase ))
                {
                    return true;
                }
            }
            return false;
        }

        
        protected virtual bool StringSubsetString( String left, String right, bool ignoreCase )
        {
            StringComparison strComp = (ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
            if (right == null || left == null || right.Length == 0 || left.Length == 0 ||
                right.Length > left.Length)
            {
                return false;
            }
            else if (right.Length == left.Length)
            {
                // if they are equal in length, just do a normal compare
                return String.Compare( right, left, strComp) == 0;
            }
            else if (left.Length - right.Length == 1 && left[left.Length-1] == m_directorySeparator)
            {
                return String.Compare( left, 0, right, 0, right.Length, strComp) == 0;
            }
            else if (right[right.Length-1] == m_directorySeparator)
            {
                // right is definitely a directory, just do a substring compare
                return String.Compare( right, 0, left, 0, right.Length, strComp) == 0;
            }
            else if (left[right.Length] == m_directorySeparator)
            {
                // left is hinting at being a subdirectory on right, do substring compare to make find out
                return String.Compare( right, 0, left, 0, right.Length, strComp) == 0;
            }
            else
            {
                return false;
            }
        }

        protected static bool StringSubsetStringPathDiscovery( String left, String right, bool ignoreCase )
        {
            StringComparison strComp = (ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
            if (right == null || left == null || right.Length == 0 || left.Length == 0)
            {
                return false;
            }
            else if (right.Length == left.Length)
            {
                // if they are equal in length, just do a normal compare
                return String.Compare( right, left, strComp) == 0;
            }
            else
            {
                String shortString, longString;

                if (right.Length < left.Length)
                {
                    shortString = right;
                    longString = left;
                }
                else
                {
                    shortString = left;
                    longString = right;
                }

                if (String.Compare( shortString, 0, longString, 0, shortString.Length, strComp) != 0)
                {
                    return false;
                }

#if !PLATFORM_UNIX
                if (shortString.Length == 3 &&
                    shortString.EndsWith( ":\\", StringComparison.Ordinal ) &&
                    ((shortString[0] >= 'A' && shortString[0] <= 'Z') ||
                    (shortString[0] >= 'a' && shortString[0] <= 'z')))
#else
                if (shortString.Length == 1 && shortString[0]== m_directorySeparator)
#endif // !PLATFORM_UNIX
                     return true;

                return longString[shortString.Length] == m_directorySeparator;
            }
        }

        
        //-------------------------------
        // protected helper functions
        //-------------------------------
        
        [SecuritySafeCritical]
        protected void AddSingleExpressionNoDuplicates( String expression )
        {
            // SafeCritical: We're not exposing out the string sets, just allowing modification of them
            int index = 0;
            
            m_expressionsArray = null;
            m_expressions = null;

            if (this.m_list == null)
                this.m_list = new ArrayList();

            while (index < this.m_list.Count)
            {
                if (StringSubsetString( (String)this.m_list[index], expression, m_ignoreCase ))
                {
                    this.m_list.RemoveAt( index );
                }
                else if (StringSubsetString( expression, (String)this.m_list[index], m_ignoreCase ))
                {
                    return;
                }
                else
                {
                    index++;
                }
            }
            this.m_list.Add( expression );
        }
    
        [System.Security.SecurityCritical]  // auto-generated
        protected void Reduce()
        {
            CheckList();
            
            if (this.m_list == null)
                return;
            
            int j;

            for (int i = 0; i < this.m_list.Count - 1; i++)
            {
                j = i + 1;
                
                while (j < this.m_list.Count)
                {
                    if (StringSubsetString( (String)this.m_list[j], (String)this.m_list[i], m_ignoreCase ))
                    {
                        this.m_list.RemoveAt( j );
                    }
                    else if (StringSubsetString( (String)this.m_list[i], (String)this.m_list[j], m_ignoreCase ))
                    {
                        // write the value at j into position i, delete the value at position j and keep going.
                        this.m_list[i] = this.m_list[j];
                        this.m_list.RemoveAt( j );
                        j = i + 1;
                    }
                    else
                    {
                        j++;
                    }
                }
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
        [SuppressUnmanagedCodeSecurity]
        internal static extern void GetLongPathName( String path, StringHandleOnStack retLongPath );

        [System.Security.SecurityCritical]  // auto-generated
        internal static String CanonicalizePath( String path )
        {
            return CanonicalizePath( path, true );
        }

        [System.Security.SecurityCritical]  // auto-generated
        internal static string CanonicalizePath(string path, bool needFullPath)
        {
            if (needFullPath)
            {
                string newPath = Path.GetFullPathInternal(path);
                if (path.EndsWith(m_directorySeparator + ".", StringComparison.Ordinal))
                {
                    if (newPath.EndsWith(m_directorySeparator))
                    {
                        newPath += ".";
                    }
                    else
                    {
                        newPath += m_directorySeparator + ".";
                    }
                }
                path = newPath;
            }
#if !PLATFORM_UNIX
            else if (path.IndexOf('~') != -1)
            {
                // GetFullPathInternal() will expand 8.3 file names
                string longPath = null;
                GetLongPathName(path, JitHelpers.GetStringHandleOnStack(ref longPath));
                path = (longPath != null) ? longPath : path;
            }

            // This blocks usage of alternate data streams and some extended syntax paths (\\?\C:\). Checking after
            // normalization allows valid paths such as " C:\" to be considered ok (as it will become "C:\").
            if (path.IndexOf(':', 2) != -1)
                throw new NotSupportedException(Environment.GetResourceString("Argument_PathFormatNotSupported"));
#endif // !PLATFORM_UNIX

            return path;
        }
    }
}