File tree Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Expand file tree Collapse file tree 4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -2444,6 +2444,21 @@ int mingw_skip_dos_drive_prefix(char **path)
2444
2444
return ret ;
2445
2445
}
2446
2446
2447
+ int mingw_known_invalid (const char * path )
2448
+ {
2449
+ // Colon is admissible as part of absolute path (e.g. "C:\file.txt")
2450
+ // but otherwise invalid. Explicit checking done to prevent
2451
+ // unintentional writing to alternate data stream path, e.g.
2452
+ // "some\path\file:streamname"
2453
+ if (path ) {
2454
+ path += has_dos_drive_prefix (path );
2455
+ for (; * path ; ++ path )
2456
+ if (* path == ':' )
2457
+ return 1 ;
2458
+ }
2459
+ return 0 ;
2460
+ }
2461
+
2447
2462
int mingw_offset_1st_component (const char * path )
2448
2463
{
2449
2464
char * pos = (char * )path ;
Original file line number Diff line number Diff line change @@ -423,6 +423,8 @@ HANDLE winansi_get_osfhandle(int fd);
423
423
(isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
424
424
int mingw_skip_dos_drive_prefix (char * * path );
425
425
#define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
426
+ int mingw_known_invalid (const char * path );
427
+ #define known_invalid mingw_known_invalid
426
428
#define has_unc_prefix (path ) (*(path) == '\\' && (path)[1] == '\\' ? 2 : 0)
427
429
#define is_dir_sep (c ) ((c) == '/' || (c) == '\\')
428
430
static inline char * mingw_find_last_dir_sep (const char * path )
Original file line number Diff line number Diff line change @@ -347,6 +347,14 @@ static inline int git_skip_dos_drive_prefix(char **path)
347
347
#define skip_dos_drive_prefix git_skip_dos_drive_prefix
348
348
#endif
349
349
350
+ #ifndef known_invalid
351
+ static inline int git_known_invalid (const char * path )
352
+ {
353
+ return 0 ;
354
+ }
355
+ #define known_invalid git_known_invalid
356
+ #endif
357
+
350
358
#ifndef has_unc_prefix
351
359
static inline int git_has_unc_prefix (const char * path )
352
360
{
Original file line number Diff line number Diff line change @@ -809,6 +809,9 @@ int verify_path(const char *path)
809
809
if (has_dos_drive_prefix (path ))
810
810
return 0 ;
811
811
812
+ if (known_invalid (path ))
813
+ return 0 ;
814
+
812
815
goto inside ;
813
816
for (;;) {
814
817
if (!c )
@@ -821,10 +824,9 @@ int verify_path(const char *path)
821
824
return 0 ;
822
825
c = * path ++ ;
823
826
if ((c == '.' && !verify_dotfile (path )) ||
824
- is_dir_sep (c ) || c == ':' || c == ' \0' )
827
+ is_dir_sep (c ) || c == '\0' )
825
828
return 0 ;
826
- } else if (c == ':' )
827
- return 0 ;
829
+ }
828
830
c = * path ++ ;
829
831
}
830
832
}
You can’t perform that action at this time.
0 commit comments