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

Add CodeQL #1037

Merged
merged 13 commits into from
Oct 16, 2023
Merged
41 changes: 41 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "CodeQL"

on:
push:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]
schedule:
- cron: '0 0 * * *'

jobs:
analyze:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
9 changes: 8 additions & 1 deletion accounts/usbwallet/trezor.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,14 @@
return 0, err
}

payload := make([]byte, 8+len(data))
var payload []byte

if 8+len(data) < 64*1024*1024 {
payload = make([]byte, 8+len(data))
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
} else {
return 0, errors.New("data too large")
}

copy(payload, []byte{0x23, 0x23})
binary.BigEndian.PutUint16(payload[2:], trezor.Type(req))
binary.BigEndian.PutUint32(payload[4:], uint32(len(data)))
Expand Down
9 changes: 9 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func (l *logger) New(ctx ...interface{}) Logger {

func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
normalizedSuffix := normalize(suffix)

if len(prefix)+len(normalizedSuffix) > 64*1024*1024 {
return make([]interface{}, 0)
}

newCtx := make([]interface{}, len(prefix)+len(normalizedSuffix))
n := copy(newCtx, prefix)
copy(newCtx[n:], normalizedSuffix)
Expand Down Expand Up @@ -326,6 +331,10 @@ type Lazy struct {
type Ctx map[string]interface{}

func (c Ctx) toArray() []interface{} {
if len(c)*2 > 64*1024*1024 {
return make([]interface{}, 0)
}

arr := make([]interface{}, len(c)*2)

i := 0
Expand Down
8 changes: 6 additions & 2 deletions p2p/enode/localnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package enode
import (
"crypto/ecdsa"
"fmt"
"math"
"net"
"reflect"
"strconv"
Expand Down Expand Up @@ -211,8 +212,11 @@ func (ln *LocalNode) SetFallbackUDP(port int) {
ln.mu.Lock()
defer ln.mu.Unlock()

ln.endpoint4.fallbackUDP = uint16(port)
ln.endpoint6.fallbackUDP = uint16(port)
if port > 0 && port <= math.MaxUint16 {
ln.endpoint4.fallbackUDP = uint16(port)
ln.endpoint6.fallbackUDP = uint16(port)
}

ln.updateEndpoints()
}

Expand Down
Loading