Small fix.

This commit is contained in:
LoRd_MuldeR 2021-06-09 20:10:16 +02:00
parent 34d8e2fc39
commit 1b49e606f8
2 changed files with 14 additions and 14 deletions

View File

@ -24,32 +24,32 @@ index 98e13bc..2fcd28f 100644
+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 *cacert = NULL; + 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) {
+#ifdef UNICODE +#ifdef UNICODE
+ char *filename_utf8 = curlx_convert_wchar_to_UTF8(filename); + char *filename_utf8 = curlx_convert_wchar_to_UTF8(filename);
+ char *execpath_utf8 = curlx_convert_wchar_to_UTF8(filebuffer); + char *exedir_utf8 = curlx_convert_wchar_to_UTF8(filebuffer);
+ if (filename_utf8 && execpath_utf8) { + if (filename_utf8 && exedir_utf8) {
+ char *lastdirchar = strrchr(execpath_utf8, '\\'); + char *lastdirchar = strrchr(exedir_utf8, '\\');
+ if(lastdirchar) { + if(lastdirchar) {
+ *lastdirchar = '\0'; + *lastdirchar = '\0';
+ } + }
+ cacert = curl_maprintf("%s%s%s", execpath_utf8, DIR_CHAR, filename_utf8); + full_path = curl_maprintf("%s%s%s", exedir_utf8, DIR_CHAR, filename_utf8);
+ } + }
+ free(filename_utf8); + free(filename_utf8);
+ free(execpath_utf8); + free(exedir_utf8);
+#else +#else
+ char *lastdirchar = strrchr(filebuffer, '\\'); + char *lastdirchar = strrchr(filebuffer, '\\');
+ if(lastdirchar) { + if(lastdirchar) {
+ *lastdirchar = '\0'; + *lastdirchar = '\0';
+ } + }
+ cacert = curl_maprintf("%s%s%s", filebuffer, DIR_CHAR, filename); + full_path = curl_maprintf("%s%s%s", filebuffer, DIR_CHAR, filename);
+#endif +#endif
+ } + }
+ return cacert; + return full_path;
+} +}
+ +
CURLcode FindWin32CACert(struct OperationConfig *config, CURLcode FindWin32CACert(struct OperationConfig *config,
@ -75,7 +75,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, &result); + char *cacert = execpath(bundle_file);
+ if (cacert) { + if (cacert) {
+ if (file_exists(cacert)) { + if (file_exists(cacert)) {
+ Curl_safefree(config->cacert); + Curl_safefree(config->cacert);

View File

@ -21,18 +21,18 @@ index d26774f..ab1d28f 100644
+ 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 +#ifdef UNICODE
+ char *execpath_utf8 = curlx_convert_wchar_to_UTF8(filebuffer); + char *exedir_utf8 = curlx_convert_wchar_to_UTF8(filebuffer);
+ if (execpath_utf8) { + if (exedir_utf8) {
+ char *lastdirchar = strrchr(execpath_utf8, '\\'); + char *lastdirchar = strrchr(exedir_utf8, '\\');
+ if(lastdirchar) { + if(lastdirchar) {
+ *lastdirchar = '\0'; + *lastdirchar = '\0';
+ } + }
+ char *full_path = curl_maprintf("%s%s%s", execpath_utf8, DIR_CHAR, filename); + char *full_path = curl_maprintf("%s%s%s", exedir_utf8, DIR_CHAR, filename);
+ if (full_path) { + if (full_path) {
+ file = fopen(full_path, FOPEN_READTEXT); + file = fopen(full_path, FOPEN_READTEXT);
+ free(full_path); + free(full_path);
+ } + }
+ free(execpath_utf8); + free(exedir_utf8);
+ } + }
+#else +#else
char *lastdirchar = strrchr(filebuffer, '\\'); char *lastdirchar = strrchr(filebuffer, '\\');