semgrep / semgrep

Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.
https://semgrep.dev
GNU Lesser General Public License v2.1
10.39k stars 602 forks source link

Pattern is not of type 'array' #5786

Closed prathya95 closed 2 years ago

prathya95 commented 2 years ago

I am trying to write the following rule: `patterns: | #CWE-285

  - pattern: |
    ...

    $THIS = $LOC.objects.filter(...)[$NUM]

    if $THIS:

      $X = $Y.objects.filter(...).order_by(...)

    ...`

For the following code: `... try:

  thislocation = Location.objects.filter(service_account = request.user)[0]

    if thislocation:

      visits = Visit.objects.filter(location = thislocation).order_by('-arrival')

...`

But I am getting the following error message, that the above semgrep rule is not of type 'array'. Any idea how to go about this?

r2c-demo commented 2 years ago

This issue is synced in Linear at https://linear.app/r2c/issue/PA-1665/pattern-is-not-of-type-array. Note: this link is for r2c use only and is not accessible publicly.

ievans commented 2 years ago

@prathya95 would you mind sharing a link from https://semgrep.live as a reproduction?

stale[bot] commented 2 years ago

This issue is being marked stale because there hasn't been any activity in 14 days and either it wasn't prioritized or its priority is high. Please apply the appropriate priority:* label before removing the stale label.

kopecs commented 2 years ago

Closing for now. If you're able to share some more details so we can reproduce this, feel free to open a new issue!