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

Support ellipsis metavariables for parameters #4420

Closed
sfc-gh-nsfard opened this issue Dec 13, 2021 · 2 comments · Fixed by #4426
Closed

Support ellipsis metavariables for parameters #4420

sfc-gh-nsfard opened this issue Dec 13, 2021 · 2 comments · Fixed by #4426

Comments

@sfc-gh-nsfard
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

I'd like to extract a java method signature (including arguments) into a metavariable.

Describe the solution you'd like
A clear and concise description of what you want to happen.

The ellipsis metavariable can be used in a message and print out all arguments.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

for example, given the following java snippet:

public class ClassA {
  public void func(MyObj obj) {
    obj.writeObj("object");
  }
}

and the following rule:

rules:
- id: blah
  patterns:
    - pattern: (MyObj $OBJ).writeObj(...);
    - pattern-inside: |
        $RT $METHOD($...ARGS) {
          ...
        }
  message: $METHOD($...ARGS)
  languages: [java]
  severity: INFO

I'd like to see the message: func(MyObj obj)

@emjin emjin added lang:java pattern:ellipsis bug Something isn't working labels Dec 13, 2021
@emjin
Copy link
Collaborator

emjin commented Dec 13, 2021

Thanks for filing this report! What priority would you say this issue is to you (high/medium/low)?

@sfc-gh-nsfard
Copy link
Author

medium is fine, thanks @emjin

aryx added a commit that referenced this issue Dec 14, 2021
This closes #4420

test plan:
test file included
also
```
$ semgrep-core -lang java -f tests/java/metavar_ellipsis_params.sgrep
tests/java/metavar_ellipsis_params.java -json | jq
...
"$...ARGS": {
            "start": {
              "line": 3,
              "col": 22,
              "offset": 62
            },
            "end": {
              "line": 3,
              "col": 40,
              "offset": 80
            },
            "abstract_content": "MyObj obj int foo",
            "unique_id": {
              "type": "AST",
              "md5sum": "3effe914fd5c6a02c7ce112d21781dfe"
            }
```
@aryx aryx mentioned this issue Dec 14, 2021
3 tasks
aryx added a commit that referenced this issue Dec 14, 2021
This closes #4420

test plan:
test file included
also
```
$ semgrep-core -lang java -f tests/java/metavar_ellipsis_params.sgrep
tests/java/metavar_ellipsis_params.java -json | jq
...
"$...ARGS": {
            "start": {
              "line": 3,
              "col": 22,
              "offset": 62
            },
            "end": {
              "line": 3,
              "col": 40,
              "offset": 80
            },
            "abstract_content": "MyObj obj int foo",
            "unique_id": {
              "type": "AST",
              "md5sum": "3effe914fd5c6a02c7ce112d21781dfe"
            }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants