From eeba3affa5b1b4bb967a401cf9585b99feb7cbe2 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 22 Apr 2012 00:23:14 +0200 Subject: [PATCH] Fixed issue #1136: Proxy password with @ symbol not parsed/saved correctly Signed-off-by: Sven Strickroth --- src/Changelog.txt | 1 + src/TortoiseProc/Settings/SetProxyPage.cpp | 58 +++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 0c98d2f1f..e7b86d955 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -9,6 +9,7 @@ * Fixed issue #1131: "Whole project" checkbox in commit dialog selects all files * Fixed issue #1065: Explorer crashes when rendering a file conflict icon * Fixed issue #1027: When post-receive hook contains more than 1 echo bash command, only the LAST echo is displayed in dialog + * Fixed issue #1136: Proxy password with @ symbol not parsed/saved correctly = Release 1.7.8.0 = == Features== diff --git a/src/TortoiseProc/Settings/SetProxyPage.cpp b/src/TortoiseProc/Settings/SetProxyPage.cpp index de03f1489..8be02137e 100644 --- a/src/TortoiseProc/Settings/SetProxyPage.cpp +++ b/src/TortoiseProc/Settings/SetProxyPage.cpp @@ -74,7 +74,35 @@ BEGIN_MESSAGE_MAP(CSetProxyPage, ISettingsPropPage) ON_BN_CLICKED(IDC_SSHBROWSE, OnBnClickedSshbrowse) END_MESSAGE_MAP() +HRESULT StringEscape(const CString& str_in, CString* escaped_string) { + // http://tools.ietf.org/html/rfc3986#section-3.2.1 + if (!escaped_string) + return E_INVALIDARG; + + DWORD buf_len = INTERNET_MAX_URL_LENGTH + 1; + HRESULT hr = ::UrlEscape(str_in, escaped_string->GetBufferSetLength(buf_len), &buf_len, URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY); + if (SUCCEEDED(hr)) { + escaped_string->ReleaseBuffer(); + } + + escaped_string->Replace(_T("@"), _T("%40")); + escaped_string->Replace(_T(":"), _T("%3a")); + return hr; +} + +HRESULT StringUnescape(const CString& str_in, CString* unescaped_string) { + if (!unescaped_string) + return E_INVALIDARG; + + DWORD buf_len = INTERNET_MAX_URL_LENGTH + 1; + HRESULT hr = ::UrlUnescape(str_in.AllocSysString(), unescaped_string->GetBufferSetLength(buf_len), &buf_len, 0); + if (SUCCEEDED(hr)) { + unescaped_string->ReleaseBuffer(); + } + + return hr; +} BOOL CSetProxyPage::OnInitDialog() { @@ -125,13 +153,13 @@ BOOL CSetProxyPage::OnInitDialog() username = proxy.Find(_T(":"),start); if(username<=0 || username >at) { - m_username=proxy.Mid(start, at-start); + StringUnescape(proxy.Mid(start, at - start), &m_username); m_password=_T(""); } else if(username < at) { - m_username=proxy.Mid(start, username-start); - m_password=proxy.Mid(username+1,at - username-1); + StringUnescape(proxy.Mid(start, username - start), &m_username); + StringUnescape(proxy.Mid(username + 1, at - username - 1), &m_password); } port=proxy.Find(_T(":"),at); @@ -214,18 +242,31 @@ BOOL CSetProxyPage::OnApply() if(m_serveraddress.Left(5) != _T("http:")) http_proxy=_T("http://"); - if(!m_username.IsEmpty()) { - http_proxy += m_username; + CString escapedUsername; + + if (StringEscape(m_username, &escapedUsername)) + { + ::MessageBox(NULL, _T("Could not encode username."), _T("TortoiseGit"), MB_ICONERROR); + return FALSE; + } + + http_proxy += escapedUsername; if(!m_password.IsEmpty()) - http_proxy += _T(":")+m_password; + { + CString escapedPassword; + if (StringEscape(m_password, &escapedPassword)) + { + ::MessageBox(NULL, _T("Could not encode password."), _T("TortoiseGit"), MB_ICONERROR); + return FALSE; + } + http_proxy += _T(":") + escapedPassword; + } http_proxy += _T("@"); - } - http_proxy+=m_serveraddress; if(m_serverport) @@ -248,7 +289,6 @@ BOOL CSetProxyPage::OnApply() return ISettingsPropPage::OnApply(); } - void CSetProxyPage::OnBnClickedSshbrowse() { CString openPath; -- 2.11.4.GIT