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

No issue reported for slice bounds out of range which causes panic #954

Closed
domsolutions opened this issue Apr 29, 2023 · 3 comments
Closed

Comments

@domsolutions
Copy link

Summary

No issue reported for resclicing a slice whose length is smaller than the reslice upper limit. Could lead to DoS attacks. Staticcheck also doesn't seem to alert on this.

Steps to reproduce the behavior

Run against

package main

import "fmt"

func main() {

	bb := make([]byte, 0)

	fmt.Println(bb[:3])

}

Reports no errors

dominic@dominic-XPS-15-9550:~/go/src/github.com/securego/gosec(master)$ ./gosec /home/dominic/go/src/github.com/securego/gosec/cmd/buggy
[gosec] 2023/04/29 09:45:39 Including rules: default
[gosec] 2023/04/29 09:45:39 Excluding rules: default
[gosec] 2023/04/29 09:45:39 Import directory: /home/dominic/go/src/github.com/securego/gosec/cmd/buggy
[gosec] 2023/04/29 09:45:39 Checking package: main
[gosec] 2023/04/29 09:45:39 Checking file: /home/dominic/go/src/github.com/securego/gosec/cmd/buggy/my-buggy-code.go
Results:


Summary:
  Gosec  : dev
  Files  : 1
  Lines  : 11
  Nosec  : 0
  Issues : 0

dominic@dominic-XPS-15-

gosec version

Latest from master

Go version (output of 'go version')

go version go1.19 linux/amd64

Operating system / Environment

Ubuntu 18.04

Expected behavior

Maybe report an error length has not been verified so may cause a panic?

Actual behavior

No issue reported.

@ccojocar
Copy link
Member

ccojocar commented May 3, 2023

Thanks for reporting this. This looks like a good enhancement but probably can be detected only a constant slice bound.

@morgenm
Copy link
Contributor

morgenm commented Jun 17, 2023

I created this PR for this: #973

@ccojocar
Copy link
Member

fixed by #973

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

No branches or pull requests

3 participants