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

How to match backticks ... or eval() #31

Open
tmuras opened this issue Sep 25, 2019 · 5 comments
Open

How to match backticks ... or eval() #31

tmuras opened this issue Sep 25, 2019 · 5 comments

Comments

@tmuras
Copy link
Contributor

tmuras commented Sep 25, 2019

How to match ls -al fragment in code like:
$output = ls -al;

@tmuras
Copy link
Contributor Author

tmuras commented Nov 12, 2019

Related to this - is there a way to match PHP language constructs?

For the source code like:

<?php
eval("echo 123");

This will not return any match:

phpgrep eval_test.php 'eval(${"*"})'

@tmuras tmuras changed the title How to match backticks ... How to match backticks ... or eval() Nov 12, 2019
@quasilyte
Copy link
Owner

I'll take a look today.
If it doesn't match eval, it's probably easy to fix.

Backticks, on the other hand, need more thoughts.
We can introduce ${"exec"} pseudo-node in addition to ${"str"}, so you can match exec with any content.

Right now you can use matcher var filter:

phpgrep hello.php '${"x:expr"}' 'x~^`.*`$'
hello.php:2: `ls .`
hello.php:3: `echo 123`

We match all expressions then check that they start with ` and end with a same character.

hello.php:

<?php
$v = `ls .`;
`echo 123`;
echo 123;

@tmuras
Copy link
Contributor Author

tmuras commented Nov 12, 2019

That actually works for me just fine - thanks for the hint!

@quasilyte
Copy link
Owner

quasilyte commented Nov 12, 2019

I also noticed that your initial question was asked on the 25th of September.
For some reason, I haven't noticed it until the recent update. Sorry for the late response.

I think eval is properly handled now, there is even a test case for it. :)

$ phpgrep hello.php 'eval($x)'
hello.php:3: eval('123')
hello.php:5: eval('$x = 1')
$ cat hello.php 
<?php

eval('123');
function f() {
  eval('$x = 1');
}

@quasilyte
Copy link
Owner

quasilyte commented Nov 12, 2019

Oh, ${"*"} is not handled properly inside of eval, now I see it.
Try using eval($_) or eval($x), since it only accepts at most argument.

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

No branches or pull requests

2 participants