Skip to content

Commit 2ba24dc

Browse files
authored
Fix segmentation fault caused by infinite recursion and unsafe array … (#213)
* Fix segmentation fault caused by infinite recursion and unsafe array access - Fix infinite recursion in ProcessUtils::runCommand(): skip javaExe() call when searching for java via which/where commands to prevent recursive loop - Fix unsafe array access in VersionResolveWorker::resolve(): add isEmpty() check before accessing result.output[0] when checking Java version The segfault occurred because runCommand() called javaExe() to set JAVA_HOME, which called findInPath() that called runCommand(which, java) again, creating an infinite recursion loop. * Removed accident build directory
1 parent 3aa12f5 commit 2ba24dc

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

sources/processutils.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ ProcessResult ProcessUtils::runCommand(const QString &exe, const QStringList &ar
139139
}
140140

141141
// Set JAVA_HOME for all commands when Java location is known
142+
// But skip if we're searching for java itself (which/where commands)
142143
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
143-
QString javaPath = ProcessUtils::javaExe(); // Get Java path from settings
144+
QString javaPath;
145+
if (actualExe != "which" && actualExe != "where") {
146+
javaPath = ProcessUtils::javaExe(); // Get Java path from settings
147+
}
144148
if (!javaPath.isEmpty()) {
145149
QFileInfo javaInfo(javaPath);
146150
QString javaHome = javaInfo.absolutePath();
@@ -167,8 +171,12 @@ ProcessResult ProcessUtils::runCommand(const QString &exe, const QStringList &ar
167171
process.start(actualExe, actualArgs, QIODevice::ReadOnly);
168172
#else
169173
// Set JAVA_HOME for all commands when Java location is known
174+
// But skip if we're searching for java itself (which/where commands)
170175
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
171-
QString javaPath = ProcessUtils::javaExe(); // Get Java path from settings
176+
QString javaPath;
177+
if (exe != "which" && exe != "where") {
178+
javaPath = ProcessUtils::javaExe(); // Get Java path from settings
179+
}
172180
if (!javaPath.isEmpty()) {
173181
QFileInfo javaInfo(javaPath);
174182
QString javaHome = javaInfo.absolutePath();

sources/versionresolveworker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void VersionResolveWorker::resolve()
2525
#ifdef QT_DEBUG
2626
qDebug() << "Java returned code" << result.code;
2727
#endif
28-
if (result.code == 0) {
28+
if ((result.code == 0) && !result.output.isEmpty()) {
2929
#ifdef QT_DEBUG
3030
qDebug() << "Java returned" << result.output[0];
3131
#endif

0 commit comments

Comments
 (0)