Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7670 - Fixed Windows chromium-args 260 character limit #7671

Open
wants to merge 1 commit into
base: nw51
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/nw_package.cc
Expand Up @@ -471,15 +471,30 @@ void Package::ReadChromiumArgs() {
// Expand Windows psudovars (ex; %APPDATA%) passed in chromium-args in the same way as when
// passed as command line parameters.
#if defined(OS_WIN)
TCHAR szEnvPath[MAX_PATH];
std::wstring ws;
ws.assign( args.begin(), args.end());
if (ExpandEnvironmentStrings(ws.c_str(), szEnvPath,MAX_PATH) != 0) {
std::wstring ws_out = szEnvPath;
args = std::string(ws_out.begin(), ws_out.end());
} else {
ReportError("Failed to expand chromium args",args.c_str());
ws.assign(args.begin(), args.end());
DWORD szEnvPathSize = ws.size();
if (szEnvPathSize > 32000) {
// ExpandEnvironmentStrings is limited to a string length of 32,000. This is unlikely to happen for chromium-args, but it could be an issue, so tell the user.
ReportError("ExpandEnvironmentStrings does not support strings over 32,000 characters for chromium-args on Windows. Open an issue if you require this.", args.c_str());
}
DWORD szEnvPathNewSize;
do {
TCHAR szEnvPath[szEnvPathSize];
szEnvPathNewSize = ExpandEnvironmentStrings(ws.c_str(), szEnvPath, szEnvPathSize);
if (szEnvPathNewSize == 0) {
ReportError("Failed to execute ExpandEnvironmentStrings on chromium-args", args.c_str());
break;
} else if (szEnvPathNewSize <= szEnvPathSize) {
// ExpandEnvironmentStrings ran without error and szEnvPath was large enough to hold the result
std::wstring ws_out = szEnvPath;
args = std::string(ws_out.begin(), ws_out.end());
break;
} else {
// Resize szEnvPath to be the size of szEnvPathNewSize
szEnvPathSize = szEnvPathNewSize;
}
} while (true);
#endif
args = env_args + kChromiumArgsSeparator + args;

Expand Down