Fix upper-bound limit of command line for "Run External Program" in Windows. Closes #5399.

This commit is contained in:
Chocobo1 2016-06-21 14:28:01 +08:00
parent 5e114c0f2e
commit 705d7730dc

View File

@ -262,8 +262,9 @@ void Application::runExternalProgram(BitTorrent::TorrentHandle *const torrent) c
QProcess::startDetached(QLatin1String("/bin/sh"), {QLatin1String("-c"), program}); QProcess::startDetached(QLatin1String("/bin/sh"), {QLatin1String("-c"), program});
#elif defined(Q_OS_WIN) // test cmd: `echo "%F" > "c:\ab ba.txt"` #elif defined(Q_OS_WIN) // test cmd: `echo "%F" > "c:\ab ba.txt"`
program.prepend(QLatin1String("cmd.exe /C ")); program.prepend(QLatin1String("cmd.exe /C "));
if (program.size() >= MAX_PATH) { const uint cmdMaxLength = 32768; // max length (incl. terminate char) for `lpCommandLine` in `CreateProcessW()`
logger->addMessage(tr("Torrent: %1, run external program command too long (length > %2), execution failed.").arg(torrent->name()).arg(MAX_PATH), Log::CRITICAL); if ((program.size() + 1) > cmdMaxLength) {
logger->addMessage(tr("Torrent: %1, run external program command too long (length > %2), execution failed.").arg(torrent->name()).arg(cmdMaxLength), Log::CRITICAL);
return; return;
} }