-
Notifications
You must be signed in to change notification settings - Fork 133
WIP: feat: using activation script to initialize the terminal #1377
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||||||||||
| package com.espressif.idf.terminal.connector.launcher; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||
| import java.io.OutputStream; | ||||||||||||||||||||||||||||||||||||||
| import java.nio.charset.StandardCharsets; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import org.eclipse.core.runtime.Platform; | ||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; | ||||||||||||||||||||||||||||||||||||||
| import org.eclipse.tm.terminal.connector.process.ProcessConnector; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import com.espressif.idf.core.IDFEnvironmentVariables; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public class IdfTerminalProcessConnector extends ProcessConnector { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static final String ENV_SCRIPT_KEY = "ESP_IDF_ACTIVATION_SCRIPT"; //$NON-NLS-1$ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||
| public void connect(ITerminalControl control) { | ||||||||||||||||||||||||||||||||||||||
| super.connect(control); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| var process = getProcess(); | ||||||||||||||||||||||||||||||||||||||
| if (process == null) { | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| String scriptPath = new IDFEnvironmentVariables().getEnvValue(ENV_SCRIPT_KEY); | ||||||||||||||||||||||||||||||||||||||
| if (scriptPath == null || scriptPath.isBlank()) { | ||||||||||||||||||||||||||||||||||||||
| writeToTerminal(process.getOutputStream(), "Error: ESP-IDF activation script path is missing.\r\n"); //$NON-NLS-1$ | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| OutputStream out = process.getOutputStream(); | ||||||||||||||||||||||||||||||||||||||
| String command; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (Platform.OS_WIN32.equals(Platform.getOS())) { | ||||||||||||||||||||||||||||||||||||||
| // Windows (PowerShell): Remove-Module: Fixes the color/white-screen issue. | ||||||||||||||||||||||||||||||||||||||
| command = "Remove-Module PSReadLine -ErrorAction SilentlyContinue; . \"" + scriptPath + "\"\r\n"; //$NON-NLS-1$ //$NON-NLS-2$ | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| // Linux / macOS (Bash/Zsh): | ||||||||||||||||||||||||||||||||||||||
| command = ". \"" + scriptPath + "\"\r\n"; //$NON-NLS-1$ //$NON-NLS-2$ | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential command injection vulnerability - sanitize script path. The Consider validating the path or escaping shell metacharacters before constructing the command. 🔎 Example mitigation approach if (Platform.OS_WIN32.equals(Platform.getOS())) {
// Windows (PowerShell): Remove-Module: Fixes the color/white-screen issue.
- command = "Remove-Module PSReadLine -ErrorAction SilentlyContinue; . \"" + scriptPath + "\"\r\n";
+ // Escape embedded quotes in path for PowerShell
+ String escapedPath = scriptPath.replace("\"", "`\"");
+ command = "Remove-Module PSReadLine -ErrorAction SilentlyContinue; . \"" + escapedPath + "\"\r\n";
} else {
// Linux / macOS (Bash/Zsh):
- command = ". \"" + scriptPath + "\"\r\n";
+ // Escape embedded quotes/special chars for shell
+ String escapedPath = scriptPath.replace("'", "'\\''");
+ command = ". '" + escapedPath + "'\r\n";
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| out.write(command.getBytes(StandardCharsets.UTF_8)); | ||||||||||||||||||||||||||||||||||||||
| out.flush(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Use proper logging instead of The project uses 🔎 Suggested fix+import com.espressif.idf.core.logging.Logger;
...
} catch (IOException e) {
- e.printStackTrace();
+ Logger.log(e);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private void writeToTerminal(OutputStream out, String message) { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| out.write(message.getBytes(StandardCharsets.UTF_8)); | ||||||||||||||||||||||||||||||||||||||
| out.flush(); | ||||||||||||||||||||||||||||||||||||||
| } catch (IOException ignored) { | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
fd -name "SetupToolsInIde.java" -type fRepository: espressif/idf-eclipse-plugin
Length of output: 302
🏁 Script executed:
Repository: espressif/idf-eclipse-plugin
Length of output: 156
🏁 Script executed:
cat -n bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/SetupToolsInIde.java | head -150Repository: espressif/idf-eclipse-plugin
Length of output: 6618
🏁 Script executed:
Repository: espressif/idf-eclipse-plugin
Length of output: 156
🏁 Script executed:
Repository: espressif/idf-eclipse-plugin
Length of output: 1163
🏁 Script executed:
Repository: espressif/idf-eclipse-plugin
Length of output: 158
🏁 Script executed:
Repository: espressif/idf-eclipse-plugin
Length of output: 3015
Add null-check for activation script path.
If
idfInstalled.getActivationScript()returnsnull, the value will be added directly to the command list inToolsUtility.getExportScriptCommand()(lines 71, 76, 80) without validation, and subsequently passed toprocessBuilderFactory.runInBackground()and the environment variables map at line 137. Validate the path before proceeding.🤖 Prompt for AI Agents