semgrep icon indicating copy to clipboard operation
semgrep copied to clipboard

increase the scope of constant propagation to the whole file (with symbolic_propagation: true)

Open ttttmr opened this issue 2 years ago • 5 comments

[Original title: javascript function variable propagation and line matching]

https://semgrep.dev/s/7Qxk

rules:
- id: bad-call
  patterns:
    - pattern-either:
      - pattern: bad(...)
  message: Found call to 'bad'
  languages: [js]
  severity: WARNING
function bad(s)
   return s

let b1=bad

b1("1")
bad("3")

I'm a beginner with semgrep and I think this should match to the b1 function call

so i modify the rules

https://semgrep.dev/s/L2oG

rules:
- id: bad-call
  patterns:
    - pattern-either:
      - pattern: bad(...)
      - pattern: |
          $X=bad
          ...
          $X(...)
  message: Found call to 'bad'
  languages: [js]
  severity: WARNING

Successfully matched, but it shows matching to line 4 and 7, I want to match to line 6 and 7

Or is there any rule writing to achieve this match, please tell me, thank you

ttttmr avatar Apr 19 '22 11:04 ttttmr

This issue is synced in Linear at https://linear.app/r2c/issue/PA-1187/javascript-function-variable-propagation-and-line-matching.

r2c-demo avatar Apr 19 '22 11:04 r2c-demo

I tried a new rule and it got stuck

rules:
- id: bad-call
  patterns:
    - pattern-either:
      - pattern: bad(...)
      - pattern:
        - pattern-inside: |
            $X=bad
            ...
        - pattern: $X(...)
  message: Found call to 'bad'
  languages: [js]
  severity: WARNING

ttttmr avatar Apr 19 '22 11:04 ttttmr

@ttttmr symbolic propagation works only within (intra) procedures right now, so if you wrap those calls in a function, it should work. See https://semgrep.dev/s/WDXj

ievans avatar Apr 19 '22 17:04 ievans

@ievans Thanks, another question is why the above rules are stuck, is this a semgrep problem, or my rules are written incorrectly

ttttmr avatar Apr 20 '22 10:04 ttttmr

To add, I can only reopen a playground in the case of being stuck. It seems that there is no place to cancel the operation. If possible, add a cancel operation, or automatically cancel the timeout. I don’t know if the backend service has a timeout limit.

ttttmr avatar Apr 20 '22 10:04 ttttmr