cURL-build-win32/patch/curl_tool_doswin.diff

94 lines
2.7 KiB
Diff
Raw Normal View History

2024-11-12 15:17:57 +01:00
src/tool_doswin.c | 60 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 43 insertions(+), 17 deletions(-)
2024-08-01 22:24:44 +02:00
diff --git a/src/tool_doswin.c b/src/tool_doswin.c
2024-11-12 15:17:57 +01:00
index 70b263113..399d49a7b 100644
2024-08-01 22:24:44 +02:00
--- a/src/tool_doswin.c
+++ b/src/tool_doswin.c
2024-11-12 15:17:57 +01:00
@@ -586,28 +586,46 @@ char **__crt0_glob_function(char *arg)
* For WinXP and later search order actually depends on registry value:
2021-06-09 19:47:18 +02:00
* HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SafeProcessSearchMode
*/
2021-06-10 01:45:25 +02:00
+static BOOL check_file_exists(const TCHAR *filename)
2021-06-09 19:47:18 +02:00
+{
2021-06-10 01:45:25 +02:00
+ const DWORD attr = GetFileAttributes(filename);
+ return (attr != INVALID_FILE_ATTRIBUTES) && (!(attr & FILE_ATTRIBUTE_DIRECTORY));
2021-06-09 19:47:18 +02:00
+}
+
+static char *execpath(const TCHAR *filename)
+{
+ static const size_t BUFFSIZE = 512;
+ TCHAR filebuffer[BUFFSIZE];
+ unsigned long len = GetModuleFileName(0, filebuffer, BUFFSIZE);
2021-06-10 01:45:25 +02:00
+ if((len > 0) && (len < BUFFSIZE)) {
+ TCHAR *lastdirchar = _tcsrchr(filebuffer, TEXT('\\'));
2021-06-09 19:47:18 +02:00
+ if(lastdirchar) {
2021-06-10 01:45:25 +02:00
+ *lastdirchar = TEXT('\0');
2021-06-09 19:47:18 +02:00
+ }
2021-06-10 01:45:25 +02:00
+ if (_tcslen(filebuffer) + _tcslen(filename) + 2U < BUFFSIZE) {
+ _tcscat(filebuffer, TEXT("\\"));
+ _tcscat(filebuffer, filename);
+ if (check_file_exists(filebuffer)) {
+#ifdef UNICODE
+ return curlx_convert_wchar_to_UTF8(filebuffer);
+#else
+ return strdup(filebuffer);
2021-06-09 19:47:18 +02:00
+#endif
2021-06-10 01:45:25 +02:00
+ }
+ }
2021-06-09 19:47:18 +02:00
+ }
2021-06-10 01:45:25 +02:00
+ return NULL;
2021-06-09 19:47:18 +02:00
+}
+
CURLcode FindWin32CACert(struct OperationConfig *config,
const TCHAR *bundle_file)
2024-11-12 15:17:57 +01:00
{
- CURLcode result = CURLE_OK;
- DWORD res_len;
- TCHAR buf[PATH_MAX];
- TCHAR *ptr = NULL;
2021-06-09 19:47:18 +02:00
-
2024-11-12 15:17:57 +01:00
- buf[0] = TEXT('\0');
2021-06-09 19:47:18 +02:00
-
2024-11-12 15:17:57 +01:00
- res_len = SearchPath(NULL, bundle_file, NULL, PATH_MAX, buf, &ptr);
- if(res_len > 0) {
- char *mstr = curlx_convert_tchar_to_UTF8(buf);
- Curl_safefree(config->cacert);
- if(mstr)
- config->cacert = strdup(mstr);
- curlx_unicodefree(mstr);
- if(!config->cacert)
- result = CURLE_OUT_OF_MEMORY;
+ char *cacert = execpath(bundle_file);
+ if (cacert) {
2021-06-10 01:45:25 +02:00
+ config->cacert = cacert;
2021-06-09 19:47:18 +02:00
}
2024-11-12 15:17:57 +01:00
- return result;
+ return CURLE_OK;
}
2024-08-01 22:24:44 +02:00
#endif
2024-11-12 15:17:57 +01:00
@@ -739,6 +757,8 @@ bool tool_isVistaOrGreater;
CURLcode win32_init(void)
{
+ size_t acmdln_len, wcmdln_len;
+
/* curlx_verify_windows_version must be called during init at least once
because it has its own initialization routine. */
if(curlx_verify_windows_version(6, 0, 0, PLATFORM_WINNT,
2024-11-12 15:17:57 +01:00
@@ -753,6 +773,12 @@ CURLcode win32_init(void)
init_terminal();
2024-08-01 22:24:44 +02:00
#endif
+ SecureZeroMemory(_acmdln, acmdln_len = strlen(_acmdln) * sizeof(char));
+ SecureZeroMemory(_wcmdln, wcmdln_len = wcslen(_wcmdln) * sizeof(wchar_t));
+
+ if (acmdln_len >= 4) strcpy(_acmdln, "curl");
+ if (wcmdln_len >= 4) wcscpy(_wcmdln, L"curl");
+
return CURLE_OK;
}