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 value escaping in codeql-env.sh #477

Merged
merged 5 commits into from
May 6, 2021
Merged

Conversation

hmakholm
Copy link
Contributor

@hmakholm hmakholm commented May 5, 2021

CodeQL itself complained (correctly) that the escaping here would fail if the value contains backslashes.

Switch to single-quoting, which is less tricky to escape.

Hmmm, how confident are we that there are not consumers that try to parse codeql-env.sh themselves and will break if they don't find double quotes? They should be using the JSON output instead, but still ...

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.

@hmakholm hmakholm force-pushed the hmakholm/pr/fix-escaping branch 2 times, most recently from 4a4a2ac to 44ebca1 Compare May 5, 2021 18:09
src/runner.ts Outdated
@@ -249,7 +249,7 @@ program
const shEnvFileContents = Object.entries(tracerConfig.env)
// Some vars contain ${LIB} that we do not want to be expanded when executing this script
.map(
([key, value]) => `export ${key}="${value.replace(/\$/g, "\\$")}"`
([key, value]) => "export " + key + "='" + value.replace(/'/g, "'\"'\"'") + "'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
([key, value]) => "export " + key + "='" + value.replace(/'/g, "'\"'\"'") + "'"
([key, value]) => `export ${key}='${value.replace(/'/g, "'\"'\"'")}'`

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Yes, it's safer to use single quotes instead of escaping the $.

@alexet
Copy link
Contributor

alexet commented May 5, 2021

I know there are consumers converting the windows output to sh (as they use bash on windows) but I don't know about users converting the sh output.

src/runner.ts Outdated Show resolved Hide resolved
@aeisenberg
Copy link
Contributor

Arrrrgh....also need to update the compile files. Let me just push a change up.

Co-authored-by: Andrew Eisenberg <[email protected]>
@hmakholm
Copy link
Contributor Author

hmakholm commented May 5, 2021

Do we need a change note warning users of the different quoting?

@aeisenberg
Copy link
Contributor

Based on how we are doing things now, the answer is no. And as we discussed, this might change, but I don't think we should be holding this PR up until we make any process changes.

@aeisenberg aeisenberg merged commit 35a83b9 into main May 6, 2021
@aeisenberg aeisenberg deleted the hmakholm/pr/fix-escaping branch May 6, 2021 16:09
@aeisenberg
Copy link
Contributor

@hmakholm, merged this for you because you mentioned earlier that you kept having merge conflicts if you waited too long.

@hmakholm
Copy link
Contributor Author

hmakholm commented May 6, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants