Skip to content

Ruby: Model the posix-spawn gem #8737

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

Merged
merged 2 commits into from
Jun 15, 2022
Merged

Ruby: Model the posix-spawn gem #8737

merged 2 commits into from
Jun 15, 2022

Conversation

hmac
Copy link
Contributor

@hmac hmac commented Apr 14, 2022

This gem exists primarily to provide methods that spawn subprocesses. We
model these as SystemCommandExecutions.

@github-actions github-actions bot added the Ruby label Apr 14, 2022
@hmac
Copy link
Contributor Author

hmac commented Apr 14, 2022

#8635 has some more complex logic for identifying which arguments are passed to the spawned process - possibly we should try to share some of that to get the same benefits here.

@hmac hmac force-pushed the hmac/posix-spawn branch from 429b9b2 to f85dc6f Compare May 24, 2022 08:22
@hmac hmac force-pushed the hmac/posix-spawn branch 6 times, most recently from 548b530 to fcf3967 Compare May 24, 2022 11:32
@hmac hmac marked this pull request as ready for review May 25, 2022 13:02
@hmac hmac requested a review from a team as a code owner May 25, 2022 13:02
@hmac hmac added the no-change-note-required This PR does not need a change note label May 26, 2022
Copy link
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

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

I have some nitpicks, but otherwise looks great.

Comment on lines 44 to 48
exists(API::Node spawn | spawn = API::getTopLevelMember("POSIX").getMember("Spawn") |
this =
posixSpawnModule()
.getAMethodCall(["spawn", "fspawn", "popen4", "pspawn", "system", "_pspawn", "`"])
)
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the spawn variable:

Suggested change
exists(API::Node spawn | spawn = API::getTopLevelMember("POSIX").getMember("Spawn") |
this =
posixSpawnModule()
.getAMethodCall(["spawn", "fspawn", "popen4", "pspawn", "system", "_pspawn", "`"])
)
this =
posixSpawnModule()
.getAMethodCall(["spawn", "fspawn", "popen4", "pspawn", "system", "_pspawn", "`"])
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, remnant of some lazy refactoring on my part...

Comment on lines 67 to 69
exists(int n, int m, DataFlow::Node otherArg |
this.argument(arg, n) and
this.argument(otherArg, m) and
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be simplified to the following, witihout loss of meaning

Suggested change
exists(int n, int m, DataFlow::Node otherArg |
this.argument(arg, n) and
this.argument(otherArg, m) and
exists(DataFlow::Node otherArg |
this.argument(arg, _) and
this.argument(otherArg, _) and

And you probably want to add and not arg = otherArg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also missed a not before the exists! Very sloppy. Should all be fixed now 🤞

)
}

private predicate argument(DataFlow::Node arg, int n) {
Copy link
Contributor

Choose a reason for hiding this comment

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

And if you take my suggestion above, then it could be simplified more by removing this n param.

hmac added 2 commits May 26, 2022 14:16
This gem exists primarily to provide methods that spawn subprocesses. We
model these as SystemCommandExecutions.
@hmac hmac force-pushed the hmac/posix-spawn branch from fcf3967 to c80a06a Compare May 26, 2022 13:29
Copy link
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@hmac hmac merged commit 7c5a838 into github:main Jun 15, 2022
@hmac hmac deleted the hmac/posix-spawn branch June 15, 2022 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants