Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EasySFTP/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern "C" int __stdcall MyMessageBoxW(HWND hWnd, LPCWSTR lpszText, LPCWSTR lpsz
lpszText = strText;
}
if (lpszCaption == NULL)
lpszCaption = (LPCWSTR) IDS_APP_TITLE;
lpszCaption = MAKEINTRESOURCEW(IDS_APP_TITLE);
if (HIWORD(lpszCaption) == 0 && lpszCaption != NULL)
{
strCaption.LoadString((UINT) LOWORD(lpszCaption));
Expand Down
24 changes: 12 additions & 12 deletions ShellDLL/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ bool CAuthentication::AssignAgentFlags(CAuthSession* pAuthSession)
if (pAuthSession->nPrevFlags == 0)
return false;
// get key type data (in the head of blob data)
DWORD dwKeyTypeLen = ConvertEndian(*((DWORD*)(pAuthSession->lpCurrentKey + 4)));
LPCSTR lpszKeyType = (LPCSTR)(pAuthSession->lpCurrentKey + 8);
DWORD dwKeyTypeLen = ConvertEndian(*reinterpret_cast<DWORD*>(pAuthSession->lpCurrentKey + 4));
LPCSTR lpszKeyType = reinterpret_cast<LPCSTR>(pAuthSession->lpCurrentKey + 8);

if ((dwKeyTypeLen == 7 && memcmp(lpszKeyType, "ssh-rsa", dwKeyTypeLen) == 0) ||
(dwKeyTypeLen == 28 && memcmp(lpszKeyType, "ssh-rsa-cert-v01@openssh.com", dwKeyTypeLen) == 0))
Expand Down Expand Up @@ -431,7 +431,7 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
pAuthSession->dwSignature = AUTH_SESSION_SIGNATURE;
pAuthSession->pAgent = pAgent;
pAuthSession->lpPageantKeyList = lpKeyList;
pAuthSession->dwKeyCount = ConvertEndian(*((DWORD*)lpKeyList));
pAuthSession->dwKeyCount = ConvertEndian(*reinterpret_cast<DWORD*>(lpKeyList));
pAuthSession->dwKeyIndex = 0;
pAuthSession->lpCurrentKey = lpKeyList + 4;
pAuthSession->nPrevFlags = -1;
Expand All @@ -447,18 +447,18 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
LPCBYTE pBlob;
size_t nBlobLen;

nBlobLen = (size_t)ConvertEndian(*((DWORD*)p));
nBlobLen = static_cast<size_t>(ConvertEndian(*reinterpret_cast<DWORD*>(p)));
pBlob = (p + 4);
p += nBlobLen + 4;

{
DWORD dwKeyTypeLen = ConvertEndian(*((DWORD*)(pBlob)));
LPCSTR lpszKeyType = (LPCSTR)(pBlob + 4);
DWORD dwKeyTypeLen = ConvertEndian(*reinterpret_cast<DWORD*>(pBlob));
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex please fix the cast type by adding const (since pBlob is LPCBYTE, which is constant)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Updated the cast at the reviewer-requested location to preserve const-correctness by changing reinterpret_cast<DWORD*>(pBlob) to reinterpret_cast<const DWORD*>(pBlob) when reading dwKeyTypeLen from pBlob (LPCBYTE). ShellDLL/Auth.cppL455
  • Committed the change on branch work as 07f0e4f with message: fix: preserve constness when reading key type length. ShellDLL/Auth.cppL455

Testing

  • ⚠️ python - <<'PY' import requests, urllib.parse q='LPCBYTE const reinterpret_cast C++' url='https://duckduckgo.com/html/?q='+urllib.parse.quote(q) print('fetch',url) r=requests.get(url,timeout=10) print(r.status_code, len(r.text)) print(r.text[:200]) PY (warning: environment limitation, requests module not installed)
  • python - <<'PY' import urllib.parse, subprocess q='LPCBYTE const reinterpret_cast C++' url='https://duckduckgo.com/html/?q='+urllib.parse.quote(q) print(url) subprocess.run(['curl','-L','-s',url],check=False) PY
  • git diff -- ShellDLL/Auth.cpp && git status --short
  • git add ShellDLL/Auth.cpp && git commit -m "fix: preserve constness when reading key type length"

View task →

LPCSTR lpszKeyType = reinterpret_cast<LPCSTR>(pBlob + 4);

// get the comment of key
DWORD dwCommentLen = ConvertEndian(*((DWORD*)p));
CMyStringW str;
str.SetUTF8String((LPCBYTE)(p + 4), static_cast<size_t>(dwCommentLen));
DWORD dwCommentLen = ConvertEndian(*reinterpret_cast<DWORD*>(p));
CMyStringW str;
str.SetUTF8String(reinterpret_cast<LPCBYTE>(p + 4), static_cast<size_t>(dwCommentLen));
p += dwCommentLen + 4;
CMyStringW strType, strDebug;
strType.SetString(lpszKeyType, dwKeyTypeLen);
Expand All @@ -485,7 +485,7 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
return LIBSSH2_ERROR_AGENT_PROTOCOL;
}
// skip signature length
auto entireLen = ConvertEndian(*((DWORD*)pSignedData));
auto entireLen = ConvertEndian(*reinterpret_cast<DWORD*>(pSignedData));
pSignedData += 4;
nSignedLen -= 4;
// skip signing method
Expand All @@ -494,7 +494,7 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
free(buff);
return LIBSSH2_ERROR_AGENT_PROTOCOL;
}
auto methodLen = ConvertEndian(*((DWORD*)pSignedData));
auto methodLen = ConvertEndian(*reinterpret_cast<DWORD*>(pSignedData));
pSignedData += 4;
nSignedLen -= 4;
if (nSignedLen < methodLen)
Expand All @@ -511,7 +511,7 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
free(buff);
return LIBSSH2_ERROR_AGENT_PROTOCOL;
}
auto signatureLen = ConvertEndian(*((DWORD*)pSignedData));
auto signatureLen = ConvertEndian(*reinterpret_cast<DWORD*>(pSignedData));
pSignedData += 4;
nSignedLen -= 4;
if (nSignedLen < signatureLen)
Expand Down
2 changes: 1 addition & 1 deletion ShellDLL/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extern "C" int __stdcall MyMessageBoxW(HWND hWnd, LPCWSTR lpszText, LPCWSTR lpsz
lpszText = strText;
}
if (lpszCaption == NULL)
lpszCaption = (LPCWSTR) IDS_APP_TITLE;
lpszCaption = MAKEINTRESOURCEW(IDS_APP_TITLE);
if (HIWORD(lpszCaption) == 0 && lpszCaption != NULL)
{
strCaption.LoadString((UINT) LOWORD(lpszCaption));
Expand Down
Loading