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

fix: removed unsafe shell when executing process #2067

Merged
merged 1 commit into from
Jun 6, 2023
Merged

Conversation

kittaakos
Copy link
Contributor

@kittaakos kittaakos commented May 11, 2023

Motivation

To eliminate the unsafe shell: true options when spawning processes. No IDE2 functionality changes are expected.

Change description

  • removed unnecessary chai-string and the corresponding type declarations,
  • cleaned up getExecPath function and removed another dependency: which, and
  • added tests for each executable provided by IDE2.

Other information

Steps to verify:

  • please put IDE2 on a path with spaces❗,
  • CLI is functional, LS works, and you can format the sketch,
  • you can flash with the firmware uploader

Ref: PNX-3671

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@kittaakos kittaakos added topic: code Related to content of the project itself topic: security Related to the protection of user data type: imperfection Perceived defect in any part of project labels May 11, 2023
@kittaakos kittaakos self-assigned this May 11, 2023
@kittaakos kittaakos force-pushed the PNX-3671 branch 2 times, most recently from d6a4900 to d69174a Compare May 12, 2023 07:03
@@ -55,7 +21,7 @@ export function spawnCommand(
stdIn?: string
): Promise<string> {
return new Promise<string>((resolve, reject) => {
const cp = spawn(command, args, { windowsHide: true, shell: true });
const cp = spawn(command, args, { windowsHide: true });
Copy link

Choose a reason for hiding this comment

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

good

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

Auto Format operation fails

The invocation of clang-format when using the "Auto Format" feature fails with the error: "Invalid value for -style"

To reproduce

  1. Create a sketch that would be modified by an "Auto Format" operation:
    void setup (){
    //foo
    }
    void loop() {}
  2. Select Tools > Auto Format from the Arduino IDE menus.
    🐛 The sketch is not formatted.
  3. Check the logs.

🐛 The logs show the clang-format command errored:

2023-05-15T06:56:48.633Z root ERROR Request format failed with error: Error executing E:\incoming\review\2067\1-e203c61\resources\app\node_modules\arduino-ide-extension\build\clang-format.exe -style="{\"AccessModifierOffset\":-2,\"AlignAfterOpenBracket\":\"Align\",\"AlignArrayOfStructures\":\"None\",\"AlignConsecutiveAssignments\":\"None\",\"AlignConsecutiveBitFields\":\"None\",\"AlignConsecutiveDeclarations\":\"None\",\"AlignConsecutiveMacros\":\"None\",\"AlignEscapedNewlines\":\"DontAlign\",\"AlignOperands\":\"Align\",\"AlignTrailingComments\":true,\"AllowAllArgumentsOnNextLine\":true,\"AllowAllConstructorInitializersOnNextLine\":true,\"AllowAllParametersOfDeclarationOnNextLine\":true,\"AllowShortBlocksOnASingleLine\":\"Always\",\"AllowShortCaseLabelsOnASingleLine\":true,\"AllowShortEnumsOnASingleLine\":true,\"AllowShortFunctionsOnASingleLine\":\"Empty\",\"AllowShortIfStatementsOnASingleLine\":\"AllIfsAndElse\",\"AllowShortLambdasOnASingleLine\":\"Empty\",\"AllowShortLoopsOnASingleLine\":true,\"AlwaysBreakAfterDefinitionReturnType\":\"None\",\"AlwaysBreakAfterReturnType\":\"None\",\"AlwaysBreakBeforeMultilineStrings\":false,\"AlwaysBreakTemplateDeclarations\":\"No\",\"AttributeMacros\":[\"__capability\"],\"BasedOnStyle\":\"LLVM\",\"BinPackArguments\":true,\"BinPackParameters\":true,\"BitFieldColonSpacing\":\"Both\",\"BraceWrapping\":{\"AfterCaseLabel\":false,\"AfterClass\":false,\"AfterControlStatement\":\"Never\",\"AfterEnum\":false,\"AfterFunction\":false,\"AfterNamespace\":false,\"AfterObjCDeclaration\":false,\"AfterStruct\":false,\"AfterUnion\":false,\"AfterExternBlock\":false,\"BeforeCatch\":false,\"BeforeElse\":false,\"BeforeLambdaBody\":false,\"BeforeWhile\":false,\"IndentBraces\":false,\"SplitEmptyFunction\":true,\"SplitEmptyRecord\":true,\"SplitEmptyNamespace\":true},\"BreakAfterJavaFieldAnnotations\":false,\"BreakBeforeBinaryOperators\":\"NonAssignment\",\"BreakBeforeBraces\":\"Attach\",\"BreakBeforeConceptDeclarations\":false,\"BreakBeforeInheritanceComma\":false,\"BreakBeforeTernaryOperators\":true,\"BreakConstructorInitializers\":\"BeforeColon\",\"BreakConstructorInitializersBeforeComma\":false,\"BreakInheritanceList\":\"BeforeColon\",\"BreakStringLiterals\":false,\"ColumnLimit\":0,\"CommentPragmas\":\"\",\"CompactNamespaces\":false,\"ConstructorInitializerAllOnOneLineOrOnePerLine\":false,\"ConstructorInitializerIndentWidth\":2,\"ContinuationIndentWidth\":2,\"Cpp11BracedListStyle\":false,\"DeriveLineEnding\":true,\"DerivePointerAlignment\":true,\"DisableFormat\":false,\"EmptyLineAfterAccessModifier\":\"Leave\",\"EmptyLineBeforeAccessModifier\":\"Leave\",\"ExperimentalAutoDetectBinPacking\":false,\"FixNamespaceComments\":false,\"ForEachMacros\":[\"foreach\",\"Q_FOREACH\",\"BOOST_FOREACH\"],\"IfMacros\":[\"KJ_IF_MAYBE\"],\"IncludeBlocks\":\"Preserve\",\"IncludeCategories\":[{\"Regex\":\"^^\\\"(llvm|llvm-c|clang|clang-c)/\",\"Priority\":2,\"SortPriority\":0,\"CaseSensitive\":false},{\"Regex\":\"^(<|\\\"(gtest^|gmock^|isl^|json)/)\",\"Priority\":3,\"SortPriority\":0,\"CaseSensitive\":false},{\"Regex\":\".*\",\"Priority\":1,\"SortPriority\":0,\"CaseSensitive\":false}],\"IncludeIsMainRegex\":\"\",\"IncludeIsMainSourceRegex\":\"\",\"IndentAccessModifiers\":false,\"IndentCaseBlocks\":true,\"IndentCaseLabels\":true,\"IndentExternBlock\":\"Indent\",\"IndentGotoLabels\":false,\"IndentPPDirectives\":\"None\",\"IndentRequires\":true,\"IndentWidth\":2,\"IndentWrappedFunctionNames\":false,\"InsertTrailingCommas\":\"None\",\"JavaScriptQuotes\":\"Leave\",\"JavaScriptWrapImports\":true,\"KeepEmptyLinesAtTheStartOfBlocks\":true,\"LambdaBodyIndentation\":\"Signature\",\"Language\":\"Cpp\",\"MacroBlockBegin\":\"\",\"MacroBlockEnd\":\"\",\"MaxEmptyLinesToKeep\":100000,\"NamespaceIndentation\":\"None\",\"ObjCBinPackProtocolList\":\"Auto\",\"ObjCBlockIndentWidth\":2,\"ObjCBreakBeforeNestedBlockParam\":true,\"ObjCSpaceAfterProperty\":false,\"ObjCSpaceBeforeProtocolList\":true,\"PPIndentWidth\":-1,\"PackConstructorInitializers\":\"BinPack\",\"PenaltyBreakAssignment\":1,\"PenaltyBreakBeforeFirstCallParameter\":1,\"PenaltyBreakComment\":1,\"PenaltyBreakFirstLessLess\":1,\"PenaltyBreakOpenParenthesis\":1,\"PenaltyBreakString\":1,\"PenaltyBreakTemplateDeclaration\":1,\"PenaltyExcessCharacter\":1,\"PenaltyIndentedWhitespace\":1,\"PenaltyReturnTypeOnItsOwnLine\":1,\"PointerAlignment\":\"Right\",\"QualifierAlignment\":\"Leave\",\"ReferenceAlignment\":\"Pointer\",\"ReflowComments\":false,\"RemoveBracesLLVM\":false,\"SeparateDefinitionBlocks\":\"Leave\",\"ShortNamespaceLines\":0,\"SortIncludes\":\"Never\",\"SortJavaStaticImport\":\"Before\",\"SortUsingDeclarations\":false,\"SpaceAfterCStyleCast\":false,\"SpaceAfterLogicalNot\":false,\"SpaceAfterTemplateKeyword\":false,\"SpaceAroundPointerQualifiers\":\"Default\",\"SpaceBeforeAssignmentOperators\":true,\"SpaceBeforeCaseColon\":false,\"SpaceBeforeCpp11BracedList\":false,\"SpaceBeforeCtorInitializerColon\":true,\"SpaceBeforeInheritanceColon\":true,\"SpaceBeforeParens\":\"ControlStatements\",\"SpaceBeforeParensOptions\":{\"AfterControlStatements\":true,\"AfterForeachMacros\":true,\"AfterFunctionDefinitionName\":false,\"AfterFunctionDeclarationName\":false,\"AfterIfMacros\":true,\"AfterOverloadedOperator\":false,\"BeforeNonEmptyParentheses\":false},\"SpaceBeforeRangeBasedForLoopColon\":true,\"SpaceBeforeSquareBrackets\":false,\"SpaceInEmptyBlock\":false,\"SpaceInEmptyParentheses\":false,\"SpacesBeforeTrailingComments\":2,\"SpacesInAngles\":\"Leave\",\"SpacesInCStyleCastParentheses\":false,\"SpacesInConditionalStatement\":false,\"SpacesInContainerLiterals\":false,\"SpacesInLineCommentPrefix\":{\"Minimum\":0,\"Maximum\":-1},\"SpacesInParentheses\":false,\"SpacesInSquareBrackets\":false,\"Standard\":\"Auto\",\"StatementAttributeLikeMacros\":[\"Q_EMIT\"],\"StatementMacros\":[\"Q_UNUSED\",\"QT_REQUIRE_VERSION\"],\"TabWidth\":2,\"UseCRLF\":false,\"UseTab\":\"Never\",\"WhitespaceSensitiveMacros\":[\"STRINGIZE\",\"PP_STRINGIZE\",\"BOOST_PP_STRINGIZE\",\"NS_SWIFT_NAME\",\"CF_SWIFT_NAME\"]}": Invalid value for -style

Expected behavior

No error from the generated clang-format command

Arduino IDE version

e203c61 (tester build for d69174a)

Operating system

Windows 11

Additional context

The fault does not occur when using the latest build from the main branch (117b2a4).


The fault occurs even with the IDE installed under a path that does not contain spaces.

@kittaakos kittaakos force-pushed the PNX-3671 branch 2 times, most recently from db14dd8 to e1b3953 Compare May 16, 2023 14:42
@kittaakos
Copy link
Contributor Author

Thank you, Per. The latest version of this PR should contain the fix. Just so you know, I removed the unique styles handling on Windows. (See #1285.) I covered the clang-format functionality with tests. They pass on both Windows and POSIX. If you can reproduce #1285, please let me know. No formatter-related changes are expected (compared with main) after my latest modifications.

@kittaakos kittaakos force-pushed the PNX-3671 branch 2 times, most recently from d3dc5b8 to 96b40c0 Compare May 16, 2023 15:17
@kittaakos
Copy link
Contributor Author

Please review. Thanks!

Copy link
Contributor

@davegarthsimpson davegarthsimpson left a comment

Choose a reason for hiding this comment

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

Code reviewed, no issues identified.

I've run the related tests locally on my intel mac and they pass.

I've also tested the IDE2 locally on the same machine and confirm the verify steps above are working, including an upload, and firmware update of the MKR WiFi 1010.

Ref: PNX-3671

Co-authored-by: per1234 <accounts@perglass.com>
Co-authored-by: Akos Kitta <a.kitta@arduino.cc>

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

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

Thanks Akos! I'm very glad that you were able to remove that hacky clang-format -style flag argument quoting code for the Windows command interpreter as part of this work.

@kittaakos kittaakos merged commit 9d2297c into main Jun 6, 2023
@kittaakos kittaakos deleted the PNX-3671 branch June 6, 2023 09:39
kittaakos pushed a commit that referenced this pull request Aug 20, 2023
Use a `string` array of command flags instead of the concatenated final
`string` command.

Ref: #2067

Closes #2179

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this pull request Aug 20, 2023
Closes #2112
Ref: #2067

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos added a commit that referenced this pull request Aug 20, 2023
Use a `string` array of command flags instead of the concatenated final
`string` command.

Ref: #2067
Closes #2179

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this pull request Aug 20, 2023
Closes #2112
Ref: #2067

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself topic: security Related to the protection of user data type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants