• Stars
    star
    446
  • Rank 94,498 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go rules for semgrep and go-ruleguard

semgrep-go

This repo holds patterns for finding odd Go code.

The rules engines currently supported:

I'll accept comby patterns if you can't get them to work with either semgrep or ruleguard.

To run a single semgrep rule:

$ semgrep -f path/to/semgrep-go/rule.yml .

To run all semgrep rules:

$ semgrep -f path/to/semgrep-go/ .

To run all the ruleguard rules:

$ ruleguard -c=0 -rules path/to/semgrep-go/ruleguard.rules.go ./...

Semgrep checks:

  • badexponentiation: check for 2^x and 10^x which look like exponentiation
  • badnilguard: check for poorly formed nil guards
  • errtodo: check for TODOs in error handling code
  • hmac-bytes: check for using bytes.Equal() with HMACs
  • hostport: check for using fmt.Sprintf() instead of net.JoinHostPort()
  • mathbits: check for places you should use math/bits instead
  • mail-address: check for using fmt.Sprintf() instead of net/mail.Address.String()
  • oddbitwise: check for odd bit-wise expressions
  • oddcompare: check for odd comparisons
  • oddcompound: check for odd compound += or -= expressions
  • oddifsequence: check for an odd sequence of ifs
  • oddmathbits: check for odd uses of math/bits
  • parseint-downcast: check for places a parsed 64-bit int is downcast to 32-bits
  • returnnil: check for odd nil-returns
  • sprinterr: check for fmt.Sprint(err) instead of err.Error()
  • joinpath: check for using strings.Join() to construct paths
  • readfull: check for extra length check for io.ReadFull()
  • nilerr: returning a nil err instead of a nil value
  • errclosed: check for call strings.Contains() to detect net.ErrClosed
  • hmac-hash: check for bad hash.New passed to hmac.New()
  • readeof: check for ignoring io.EOF as a successful read
  • writestring: check for using io.WriteString(w, string(b))
  • wronglock: find incorrect lock/unlock pairs for rwmutex
  • contexttodo: find context.TODO() usage and suggest to change it
  • close-sql-query-rows: find places database/sql.Rows instance isn't Close()d
  • unixnano: check for time.Time comparisons using UnixNano()
  • timeafter: leaky use of time.After()
  • contextCancelable: checks for cancelable contexts not systematically canceled

Ruleguard checks are in ruleguard.rules.go.

  • unconvert: check for unnecessary conversions
  • timeeq: check for using == and != with time.Time values
  • errnoterror: check for variables called err which are not the error type
  • ifbodythenbody: check for if statements with identical if and else bodies
  • subtractnoteq: check for x-y==0 instead of x==y
  • selfassign: check for variable self-assignments
  • oddnestedif: check for odd patterns of nested-ifs.
  • oddbitwise: check for odd bitwise expressions
  • ifreturn: check for off if/return sequences
  • oddifsequence: check for if sequences
  • nestedifsequence: check for odd nested if sequences
  • identicalassignments: check for x = y ; y = x pairs.
  • oddcompoundop: check for odd compound operations
  • constswitch: check for switch statements with expressions
  • oddcomparisons: check for odd comparisons
  • oddmathbits: check for odd uses of math/bits
  • floateq: check for exact comparisons of floating point values
  • badexponent: check for 2^x and 10^x , which look like exponentiation
  • floatloop: check for using floats as loop counters
  • urlredacted: check for logging urls without calling url.Redacted()
  • sprinterr: check for calling fmt.Sprint(err) instead of err.Error()
  • largeloopcopy: check for large value copies in loops
  • joinpath: check for using strings.Join() to construct paths
  • readfull: check for extra length check for io.ReadFull()
  • nilerr: returning an nil error instead of a nil value
  • errnetclosed: check for call strings.Contains() to detect net.ErrClosed
  • hmac-hash: check for bad hash.New passed to hmac.New()
  • readeof: check for ignoring io.EOF as a successful read
  • writestring: check for using io.WriteString(w, string(b)) when b is []byte
  • badlock: find incorrect lock/unlock pairs for rwmutex
  • contexttodo: find context.TODO() usage and suggest to change it _

Find this useful? Buy me a coffee!

More Repositories

1

go-perfbook

Thoughts on Go performance optimization
10,511
star
2

awesome-consensus

Awesome list for Paxos and friends
2,010
star
3

awesome-go-style

A collection of Go style guides
962
star
4

go-tsz

Time series compression algorithm from Facebook's Gorilla paper
Go
535
star
5

dgoogauth

Google Authenticator for Go
Go
419
star
6

go-jump

go-jump: Jump consistent hashing
Go
375
star
7

trifles

A playground for things that aren't interesting enough to have their own repo.
Go
330
star
8

go-tinylfu

TinyLFU cache admission policy
Go
240
star
9

go-farm

go-farm: a pure-Go farmhash implementation
Go
235
star
10

vim-godef

vim plugin providing godef support
Vim Script
219
star
11

go-simstore

simhash storage and searching
Go
137
star
12

interesting-papers

Interesting papers I'd like to implement (or at least have implementations of)
121
star
13

go-bloomindex

Bloom-filter based search index
Go
119
star
14

dkeyczar

Port of Google's Keyczar cryptography library to Go
Go
111
star
15

go-xxh3

xxh3 fast hash function
Go
104
star
16

dmrgo

Go library for writing standalone Map/Reduce jobs or for use with Hadoop's streaming protocol
Go
104
star
17

go-metro

Go translation of MetroHash
Go
95
star
18

go-maglev

Go implementation of maglev hashing
Go
93
star
19

go-topk

Streaming TopK estimates
Go
83
star
20

hokusai

hokusai -- sketching streams in real-time
Go
79
star
21

go-highway

Go implementation of Google's HighwayHash
Python
74
star
22

go-boomphf

Fast and scalable minimal perfect hashing for massive key sets
Go
71
star
23

go-lttb

Implementation of Largest-Triangle-Three-Buckets down-sampling algorithm
Go
69
star
24

go-bitstream

go-bitstream: read and write bits from io.Reader and io.Writer
Go
68
star
25

dgohash

A collection of well-known string hash functions, implemented in Go
Go
66
star
26

go-failure

Phi Accrual Failure Detection
Go
65
star
27

go-mph

minimal perfect hash functions
Go
61
star
28

go-rendezvous

rendezvous hashing
Go
61
star
29

go-ketama

Ketama implementation compatible with Algorithm::ConsistentHash::Ketama
Go
59
star
30

gttp

gttp: http for gophers
Go
58
star
31

go-identicon

Create simple visual hashes of data, similar to github's identicons.
Go
57
star
32

talks

Go
57
star
33

bread

Notes on bread baking
53
star
34

libchash

simple consistent hashing implementation
C
53
star
35

go-change

Online Change Detection Algorithm
Go
53
star
36

gophervids

Proof of concept Gopher Video player
HTML
51
star
37

go-onlinestats

One-pass running statistics
Go
51
star
38

go-gk

gk: streaming quantiles
Go
43
star
39

go-mpchash

Multi-probe consistent hashing
Go
41
star
40

go-bits

amd64 optimized bit operations
Go
41
star
41

go-pcgr

pcg random number generator
Go
40
star
42

go-minhash

BottomK minwise hashing for streaming set similarity
Go
39
star
43

go-sequitur

Sequitur algorithm for recognizing lexical structure in strings
Go
39
star
44

go-discreterand

Return random values sampled from a discrete distribution
Go
38
star
45

go-groupvarint

SSE-optimized group varint integer encoding
Go
37
star
46

go-arc

adaptive replacement cache
Go
36
star
47

go-shardedkv

sharded key-value store compatible with p5-ShardedKV
Go
35
star
48

go-trigram

Small trigram indexer
Go
34
star
49

go-wyhash

wyhash fast non-cryptographic string hash
Go
34
star
50

go-kll

KLL sketch: Almost Optimal Streaming Quantiles
Go
33
star
51

go-clockpro

go-clockpro: CLOCK-Pro cache eviction algorithm
Go
33
star
52

go-sip13

siphash 1-3
Go
33
star
53

go-ddmin

ddmin test case minimization algorithm
Go
31
star
54

go-fastquantiles

approximate streaming quantiles
Go
31
star
55

rgip

rgip: restful geoip service
Go
31
star
56

go-skip32

Skip32 integer obfuscation routines
Go
29
star
57

go-linebreak

Line breaking in linear time
Go
29
star
58

go-yubicloud

go-yubicloud: Client for Yubico's OTP Validation Service
Go
27
star
59

go-fuzzstr

Fuzzy text searching like Sublime Text
Go
26
star
60

go-cuckoof

Go implemetation of cuckoo filters
Go
26
star
61

go-s4lru

s4lru cache
Go
26
star
62

go-multiq

multiq: a relaxed, concurrent priority queue
Go
24
star
63

go-subset

deterministic subsetting
Go
24
star
64

ragel-examples

Go
23
star
65

go-duoweb

Duo Security two-factor authentication for Go web applications
Go
23
star
66

go-yubiauth

Yubikey Authorization Server
Go
23
star
67

haiku-finder

A program to search text files for sentences that match 5-7-5 a syllable count.
Go
22
star
68

go-xoshiro

xoshiro256** random number generator
Go
22
star
69

go-t1ha

Go implementation of the t1ha hash function
Go
21
star
70

go-hollow

Hollow Heaps for Go
Go
20
star
71

dpc

beginnings of a toy pascal compiler
Go
20
star
72

go-holtwinters

Holt-Winters forecasting
Go
20
star
73

go-keyless

Client and server reimplementation of CloudFlare's Keyless
Go
19
star
74

go-timewindow

Counters over sliding windows
Go
19
star
75

dgobloom

A simple Bloom Filter implementation in Go
Go
17
star
76

dhd

hexdumper with tcp proxy support
Go
17
star
77

modelchecking

model checking samples
Go
17
star
78

go-expirecache

Simple expiring cache
Go
16
star
79

go-gramgen

Simple generative fuzzer
Go
16
star
80

peachpy-examples

Python
15
star
81

go-stampede

Optimal cache stampede prevention
Go
15
star
82

go-disco

discohash
Go
15
star
83

go-xoroshiro

Go implementation of xoroshiro128+ RNG
Go
15
star
84

go-fastlz

Go implementation of FastLZ compression
Go
14
star
85

mph-rs

minimal perfect hashing for rust
Rust
13
star
86

numerical-rs

Numerical integration routines for Rust
Rust
13
star
87

go-tinymap

tinymap is a small map implementation
Go
13
star
88

go-lzo

Go wrapper for LZO compression library
Go
13
star
89

go-interp

Interpolation search
Go
12
star
90

go-zlatlong

zlatlong -- Microsoft's lat/long compression algorithm
Go
12
star
91

go-rebucket

ReBucket: group panic()s by similarity
Go
12
star
92

go-marvin32

Assembly-optimized Marvin32 hash function
Go
12
star
93

go-spooky

Spooky Hash
Go
12
star
94

go-cobs

Consistent Overhead Byte Stuffing encoding for Go
Go
11
star
95

go-postings

Search engine postings list with support for compresison
Go
11
star
96

cobs-rs

consistent overhead byte stuffing
Rust
11
star
97

go-bloomf

Simple bloom filter
Go
11
star
98

go-abitvec

atomic bitvector
Go
11
star
99

go-csnappy

go-csnappy wraps the snappy compression library
Go
11
star
100

go-siphasm

siphasm: fast amd64 siphash-2-4
Go
10
star