... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Thu Oct 29 17:27:40 CET 2009 (acab) |
|
2 |
+----------------------------------- |
|
3 |
+ * win32: don't use . or .. in UNC names |
|
4 |
+ |
|
1 | 5 |
Wed Oct 28 15:15:05 EET 2009 (edwin) |
2 | 6 |
------------------------------------ |
3 | 7 |
* clamd/thrmgr.c: use a double instead of integer to avoid negative time (bb #1731). |
... | ... |
@@ -29,7 +29,7 @@ |
29 | 29 |
|
30 | 30 |
wchar_t *uncpath(const char *path) { |
31 | 31 |
DWORD len = 0; |
32 |
- wchar_t *dest = cli_malloc((PATH_MAX + 1) * sizeof(wchar_t)); |
|
32 |
+ wchar_t *stripme, *strip_from, *dest = cli_malloc((PATH_MAX + 1) * sizeof(wchar_t)); |
|
33 | 33 |
|
34 | 34 |
if(!dest) |
35 | 35 |
return NULL; |
... | ... |
@@ -64,11 +64,37 @@ wchar_t *uncpath(const char *path) { |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
len = wcslen(dest); |
67 |
- if(len == 6 && !wcsncmp(dest, L"\\\\?\\", 4) && (dest[5] == L':') && ((dest[4] >= L'A' && dest[4] <= L'Z') || (dest[4] >= L'a' && dest[4] <= L'z'))) { |
|
68 |
- dest[6] = L'\\'; |
|
69 |
- dest[7] = L'\0'; |
|
67 |
+ strip_from = &dest[3]; |
|
68 |
+ /* append a backslash to naked drives and get rid of . and .. */ |
|
69 |
+ if(!wcsncmp(dest, L"\\\\?\\", 4) && (dest[5] == L':') && ((dest[4] >= L'A' && dest[4] <= L'Z') || (dest[4] >= L'a' && dest[4] <= L'z'))) { |
|
70 |
+ if(len == 6) { |
|
71 |
+ dest[6] = L'\\'; |
|
72 |
+ dest[7] = L'\0'; |
|
73 |
+ } |
|
74 |
+ strip_from = &dest[6]; |
|
75 |
+ } |
|
76 |
+ while((stripme = wcsstr(strip_from, L"\\."))) { |
|
77 |
+ wchar_t *copy_from, *copy_to; |
|
78 |
+ if(stripme[2] == L'\\') { |
|
79 |
+ copy_from = &stripme[2]; |
|
80 |
+ copy_to = stripme; |
|
81 |
+ } else if (stripme[2] == L'.' && stripme[3] == L'\\') { |
|
82 |
+ *stripme = L'\0'; |
|
83 |
+ copy_from = &stripme[3]; |
|
84 |
+ copy_to = wcsrchr(strip_from, L'\\'); |
|
85 |
+ if(!copy_to) |
|
86 |
+ copy_to = strip_from; |
|
87 |
+ } else { |
|
88 |
+ strip_from = &stripme[1]; |
|
89 |
+ continue; |
|
90 |
+ } |
|
91 |
+ while(1) { |
|
92 |
+ *copy_to = *copy_from; |
|
93 |
+ if(!*copy_from) break; |
|
94 |
+ copy_to++; |
|
95 |
+ copy_from++; |
|
96 |
+ } |
|
70 | 97 |
} |
71 |
- |
|
72 | 98 |
return dest; |
73 | 99 |
} |
74 | 100 |
|
... | ... |
@@ -101,9 +127,6 @@ w32_stat(const char *path, struct stat *buf) { |
101 | 101 |
if(!wpath) |
102 | 102 |
return -1; |
103 | 103 |
|
104 |
- len = wcslen(wpath); |
|
105 |
- if(len > 2 && wpath[len-1] == L'.' && wpath[len-2] == L'\\') |
|
106 |
- wpath[len-2] = L'\0'; /* windoze can't stat '.' ... */ |
|
107 | 104 |
len = GetFileAttributesExW(wpath, GetFileExInfoStandard, &attrs); |
108 | 105 |
free(wpath); |
109 | 106 |
if(!len) { |