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

A cross-function checking possibility #468

Open
jongleb opened this issue Jan 19, 2024 · 0 comments
Open

A cross-function checking possibility #468

jongleb opened this issue Jan 19, 2024 · 0 comments

Comments

@jongleb
Copy link

jongleb commented Jan 19, 2024

Please support to check if functions are called from the other. Let me show an example. Let me show an example.

This is the code I need to check. I need to check if I use an argument in concurrent mode.

  let use_thing thing = 
    let%bind () = fn1 thing
    and _ = fn2 thing in
    return ()

  let other_fn () = get_thing use_thing

And it works when this function is inside the function where get_thing is called.

rules:
  - id: concurrent-use
    patterns:
      - pattern-inside:
          pattern-either:
            - pattern: get_thing (fun $THING -> ...)
            - pattern: get_thing @@ fun $THING -> ...
            - pattern: let $FN_NAME $THING = ... in get_thing  $FN_NAME
      - pattern-either:
          - pattern: let $X = ... $THING ... and $Y = ... $THING ... in ...
          - pattern: let () = ... $THING ... and () = ... $THING ... in ...
          - pattern: let $X = ... $THING ... and () = ... $THING ... in ...
          - pattern: let () = ... $THING ... and $Y = ... $THING ... in ...
    languages:
      - ocaml
    severity: ERROR

And this could be rewritten with the following pattern (at least the same idea works for typescript and python)

rules:
  - id: concurrent-use
    patterns:
      - pattern:
            let $F $THING = ...
            ...
            get_thing  $F
      - pattern-either:
          - pattern: let $X = ... $THING ... and $Y = ... $THING ... in ...
          - pattern: let () = ... $THING ... and () = ... $THING ... in ...
          - pattern: let $X = ... $THING ... and () = ... $THING ... in ...
          - pattern: let () = ... $THING ... and $Y = ... $THING ... in ...
    message: Semgrep found a match
    languages:
      - ocaml
    severity: ERROR

But nothing is caught.

I tried this version (which is worked for typescript too):

- pattern:
            let $F $THING = ...
            ...
            let $ANOTHER_FN ... = get_thing  $F

But I caught: Invalid pattern for OCaml:

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

No branches or pull requests

1 participant