Improved patches.

This commit is contained in:
LoRd_MuldeR 2021-06-10 01:45:25 +02:00
parent 1007fd7f55
commit 14aeb0919c
2 changed files with 42 additions and 80 deletions

View File

@ -1,61 +1,46 @@
diff --git "a/D:\\_Sandbox\\curl\\curl-src\\src\\tool_doswin.c.orig" "b/D:\\_Sandbox\\curl\\curl-src\\src\\tool_doswin.c" diff --git "a/D:\\_Sandbox\\curl\\curl-src\\src\\tool_doswin.c.orig" "b/D:\\_Sandbox\\curl\\curl-src\\src\\tool_doswin.c"
index 98e13bc..2fcd28f 100644 index 98e13bc..9f83c16 100644
--- "a/src/tool_doswin.c" --- "a/src/tool_doswin.c"
+++ "b/src/tool_doswin.c" +++ "b/src/tool_doswin.c"
@@ -612,6 +612,52 @@ char **__crt0_glob_function(char *arg) @@ -612,6 +612,37 @@ char **__crt0_glob_function(char *arg)
* HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode * HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode
*/ */
+static BOOL file_exists(const char *filename) +static BOOL check_file_exists(const TCHAR *filename)
+{ +{
+ DWORD attribs = INVALID_FILE_ATTRIBUTES; + const DWORD attr = GetFileAttributes(filename);
+#ifdef UNICODE + return (attr != INVALID_FILE_ATTRIBUTES) && (!(attr & FILE_ATTRIBUTE_DIRECTORY));
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
+ if (filename_w) {
+ attribs = GetFileAttributes(filename_w);
+ free(filename_w);
+ }
+#else
+ attribs = GetFileAttributes(filename)
+#endif
+ return (attribs != INVALID_FILE_ATTRIBUTES) && (!(attribs & FILE_ATTRIBUTE_DIRECTORY));
+} +}
+ +
+static char *execpath(const TCHAR *filename) +static char *execpath(const TCHAR *filename)
+{ +{
+ static const size_t BUFFSIZE = 512; + static const size_t BUFFSIZE = 512;
+ char *full_path = NULL;
+ TCHAR filebuffer[BUFFSIZE]; + TCHAR filebuffer[BUFFSIZE];
+
+ unsigned long len = GetModuleFileName(0, filebuffer, BUFFSIZE); + unsigned long len = GetModuleFileName(0, filebuffer, BUFFSIZE);
+ if(len > 0 && len < BUFFSIZE) { + if((len > 0) && (len < BUFFSIZE)) {
+ TCHAR *lastdirchar = _tcsrchr(filebuffer, TEXT('\\'));
+ if(lastdirchar) {
+ *lastdirchar = TEXT('\0');
+ }
+ if (_tcslen(filebuffer) + _tcslen(filename) + 2U < BUFFSIZE) {
+ _tcscat(filebuffer, TEXT("\\"));
+ _tcscat(filebuffer, filename);
+ if (check_file_exists(filebuffer)) {
+#ifdef UNICODE +#ifdef UNICODE
+ char *filename_utf8 = curlx_convert_wchar_to_UTF8(filename); + return curlx_convert_wchar_to_UTF8(filebuffer);
+ char *exedir_utf8 = curlx_convert_wchar_to_UTF8(filebuffer);
+ if (filename_utf8 && exedir_utf8) {
+ char *lastdirchar = strrchr(exedir_utf8, '\\');
+ if(lastdirchar) {
+ *lastdirchar = '\0';
+ }
+ full_path = curl_maprintf("%s%s%s", exedir_utf8, DIR_CHAR, filename_utf8);
+ }
+ free(filename_utf8);
+ free(exedir_utf8);
+#else +#else
+ char *lastdirchar = strrchr(filebuffer, '\\'); + return strdup(filebuffer);
+ if(lastdirchar) {
+ *lastdirchar = '\0';
+ }
+ full_path = curl_maprintf("%s%s%s", filebuffer, DIR_CHAR, filename);
+#endif +#endif
+ } + }
+ return full_path; + }
+ }
+ return NULL;
+} +}
+ +
CURLcode FindWin32CACert(struct OperationConfig *config, CURLcode FindWin32CACert(struct OperationConfig *config,
curl_sslbackend backend, curl_sslbackend backend,
const TCHAR *bundle_file) const TCHAR *bundle_file)
@@ -627,23 +673,17 @@ CURLcode FindWin32CACert(struct OperationConfig *config, @@ -627,22 +658,10 @@ CURLcode FindWin32CACert(struct OperationConfig *config,
if((curlinfo->features & CURL_VERSION_SSL) && if((curlinfo->features & CURL_VERSION_SSL) &&
backend != CURLSSLBACKEND_SCHANNEL) { backend != CURLSSLBACKEND_SCHANNEL) {
@ -67,7 +52,9 @@ index 98e13bc..2fcd28f 100644
- -
- res_len = SearchPath(NULL, bundle_file, NULL, PATH_MAX, buf, &ptr); - res_len = SearchPath(NULL, bundle_file, NULL, PATH_MAX, buf, &ptr);
- if(res_len > 0) { - if(res_len > 0) {
- Curl_safefree(config->cacert); + char *cacert = execpath(bundle_file);
+ if (cacert) {
Curl_safefree(config->cacert);
-#ifdef UNICODE -#ifdef UNICODE
- config->cacert = curlx_convert_wchar_to_UTF8(buf); - config->cacert = curlx_convert_wchar_to_UTF8(buf);
-#else -#else
@ -75,17 +62,7 @@ index 98e13bc..2fcd28f 100644
-#endif -#endif
- if(!config->cacert) - if(!config->cacert)
- result = CURLE_OUT_OF_MEMORY; - result = CURLE_OUT_OF_MEMORY;
+ char *cacert = execpath(bundle_file);
+ if (cacert) {
+ if (file_exists(cacert)) {
+ Curl_safefree(config->cacert);
+ config->cacert = cacert; + config->cacert = cacert;
+ }
+ else
+ free(cacert);
} }
+ else
+ result = CURLE_OUT_OF_MEMORY;
} }
return result;

View File

@ -1,8 +1,8 @@
diff --git "a/D:\\_Sandbox\\curl\\curl-src\\src\\tool_parsecfg.c.orig" "b/D:\\_Sandbox\\curl\\curl-src\\src\\tool_parsecfg.c" diff --git "a/D:\\_Sandbox\\curl\\curl-src\\src\\tool_parsecfg.c.orig" "b/D:\\_Sandbox\\curl\\curl-src\\src\\tool_parsecfg.c"
index d26774f..ab1d28f 100644 index d26774f..1026630 100644
--- "a/src/tool_parsecfg.c" --- "a/src/tool_parsecfg.c"
+++ "b/src/tool_parsecfg.c" +++ "b/src/tool_parsecfg.c"
@@ -47,28 +47,39 @@ static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error); @@ -47,27 +47,26 @@ static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error);
#ifdef WIN32 #ifdef WIN32
static FILE *execpath(const char *filename) static FILE *execpath(const char *filename)
{ {
@ -14,28 +14,12 @@ index d26774f..ab1d28f 100644
- unsigned long len = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer)); - unsigned long len = GetModuleFileNameA(0, filebuffer, sizeof(filebuffer));
- if(len > 0 && len < sizeof(filebuffer)) { - if(len > 0 && len < sizeof(filebuffer)) {
- /* We got a valid filename - get the directory part */ - /* We got a valid filename - get the directory part */
- char *lastdirchar = strrchr(filebuffer, '\\');
+ static const size_t BUFFSIZE = 512; + static const size_t BUFFSIZE = 512;
+ FILE *file = NULL;
+ TCHAR filebuffer[BUFFSIZE]; + TCHAR filebuffer[BUFFSIZE];
+
+ unsigned long len = GetModuleFileName(0, filebuffer, BUFFSIZE); + unsigned long len = GetModuleFileName(0, filebuffer, BUFFSIZE);
+ if(len > 0 && len < BUFFSIZE) { + if((len > 0) && (len < BUFFSIZE)) {
+#ifdef UNICODE + TCHAR *lastdirchar = _tcsrchr(filebuffer, TEXT('\\'));
+ char *exedir_utf8 = curlx_convert_wchar_to_UTF8(filebuffer);
+ if (exedir_utf8) {
+ char *lastdirchar = strrchr(exedir_utf8, '\\');
+ if(lastdirchar) {
+ *lastdirchar = '\0';
+ }
+ char *full_path = curl_maprintf("%s%s%s", exedir_utf8, DIR_CHAR, filename);
+ if (full_path) {
+ file = fopen(full_path, FOPEN_READTEXT);
+ free(full_path);
+ }
+ free(exedir_utf8);
+ }
+#else
char *lastdirchar = strrchr(filebuffer, '\\');
if(lastdirchar) { if(lastdirchar) {
- size_t remaining; - size_t remaining;
- *lastdirchar = 0; - *lastdirchar = 0;
@ -43,24 +27,25 @@ index d26774f..ab1d28f 100644
- remaining = sizeof(filebuffer) - strlen(filebuffer); - remaining = sizeof(filebuffer) - strlen(filebuffer);
- if(strlen(filename) < remaining - 1) { - if(strlen(filename) < remaining - 1) {
- msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename); - msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename);
- return fopen(filebuffer, FOPEN_READTEXT); + *lastdirchar = TEXT('\0');
- }
+ *lastdirchar = '\0';
+ } + }
+ char *full_path = curl_maprintf("%s%s%s", filebuffer, DIR_CHAR, filename); + if (_tcslen(filebuffer) + _tcslen(filename) + 2U < BUFFSIZE) {
+ if (full_path) { + _tcscat(filebuffer, TEXT("\\"));
+ file = fopen(full_path, FOPEN_READTEXT); + _tcscat(filebuffer, filename);
+ free(full_path); + if (exists(filebuffer)) {
} +#ifdef UNICODE
+ return _wfopen(filebuffer, TEXT(FOPEN_READTEXT));
+#else
return fopen(filebuffer, FOPEN_READTEXT);
+#endif +#endif
} }
}
}
- -
- return NULL; return NULL;
+ return file;
} }
#endif #endif
@@ -85,7 +84,7 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
@@ -85,7 +96,7 @@ int parseconfig(const char *filename, struct GlobalConfig *global)
if(!filename || !*filename) { if(!filename || !*filename) {
/* NULL or no file name attempts to load .curlrc from the homedir! */ /* NULL or no file name attempts to load .curlrc from the homedir! */