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

Fix gosec warnings #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions input_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (p *WindowsParser) TearDown() error {
// Read returns byte array.
func (p *WindowsParser) Read() ([]byte, error) {
var ev uint32
// #nosec G103
r0, _, err := procGetNumberOfConsoleInputEvents.Call(p.tty.Input().Fd(), uintptr(unsafe.Pointer(&ev)))
if r0 == 0 {
return nil, err
Expand Down
13 changes: 12 additions & 1 deletion internal/bisect/bisect_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package bisect_test

import (
"encoding/binary"
"fmt"
"math/rand"
"testing"

crypto_rand "crypto/rand"
math_rand "math/rand"

"github.com/c-bata/go-prompt/internal/bisect"
)

Expand Down Expand Up @@ -34,7 +38,14 @@ func TestBisectRight(t *testing.T) {
}

func BenchmarkRight(b *testing.B) {
rand.Seed(0)
// https://stackoverflow.com/a/54491783/6309
var bb [8]byte
_, err := crypto_rand.Read(bb[:])
if err != nil {
panic("cannot seed math/rand package with cryptographically secure random number generator")
}
// Avoid G404: Use of weak random number generator (math/rand instead of crypto/rand)
math_rand.Seed(int64(binary.LittleEndian.Uint64(bb[:])))

for _, l := range []int{10, 1e2, 1e3, 1e4} {
x := rand.Perm(l)
Expand Down
3 changes: 2 additions & 1 deletion internal/debug/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var (
func init() {
if e := os.Getenv(envEnableLog); e == "true" || e == "1" {
var err error
logfile, err = os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
// Avoid G302: Expect file permissions to be 0600 or less
logfile, err = os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err == nil {
logger = log.New(logfile, "", log.Llongfile)
return
Expand Down