id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c24600
found { return rules } return []Rule{} }
c24601
:= range s.patterns { if !pattern.MatchString(str) { return false } } return true }
c24602
if node, ok := file.Scope.Objects[n.String()]; ok { return node.Kind != ast.Var && node.Kind != ast.Fun } } return false }
c24603
}, MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: "SQL string concatenation", }, }, }, []ast.Node{(*ast.BinaryExpr)(nil)} }
c24604
gosec.Medium, Confidence: gosec.High, What: "SQL string formatting", }, }, } rule.calls.AddAll("fmt", "Sprint", "Sprintf", "Sprintln", "Fprintf") rule.noIssue.AddAll("os", "Stdout", "Stderr") rule.noIssueQuoted.Add("github.com/lib/pq", "QuoteIdentifier") return rule, []ast.Node{(*ast.CallExpr)(...
c24605
if err = json.Unmarshal(data, &c); err != nil { return int64(len(data)), err } return int64(len(data)), nil }
c24606
int64(len(data)), err } return io.Copy(w, bytes.NewReader(data)) }
c24607
%s not in configuration", section) } return settings, nil }
c24608
nil } return "", fmt.Errorf("global setting for %s not found", option) } } return "", fmt.Errorf("no global config options found") }
c24609
:= globals.(map[GlobalOption]string); ok { settings[option] = value } } }
c24610
return false, err } return (value == "true" || value == "enabled"), nil }
c24611
"Use of weak random number generator (math/rand instead of crypto/rand)", }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24612
MetaData: gosec.MetaData{ ID: id, What: "Use of ssh InsecureIgnoreHostKey should be audited", Severity: gosec.Medium, Confidence: gosec.High, }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24613
whitelist.AddAll(key, val...) } } } return &noErrorCheck{ MetaData: gosec.MetaData{ ID: id, Severity: gosec.Low, Confidence: gosec.High, What: "Errors unhandled.", }, whitelist: whitelist, }, []ast.Node{(*ast.AssignStmt)(nil), (*ast.ExprStmt)(nil)} }
c24614
ID: id, What: "Use of math/big.Int.Exp function should be audited for modulus == 0", Severity: gosec.Low, Confidence: gosec.High, }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24615
:= range rl { builders[def.ID] = def.Create } return builders }
c24616
DES, RC4, MD5 or SHA1", NewUsesWeakCryptography}, {"G402", "Look for bad TLS connection settings", NewIntermediateTLSCheck}, {"G403", "Ensure minimum RSA key length of 2048 bits", NewWeakKeyStrength}, {"G404", "Insecure random number source (rand)", NewWeakRandCheck}, // blacklist {"G501", "Import blacklist...
c24617
line, Column: column, Err: err, } }
c24618
int) bool { if errors[i].Line == errors[j].Line { return errors[i].Column <= errors[j].Column } return errors[i].Line < errors[j].Line }) } }
c24619
args: regexp.MustCompile(`^/tmp/.*$|^/var/tmp/.*$`), MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: "File creation in shared tmp directory without using ioutil.Tempfile", }, }, []ast.Node{(*ast.CallExpr)(nil)} }
c24620
make(map[string]string), make(map[string]bool), } }
c24621
if len(parts) > 0 { name := parts[len(parts)-1] t.Imported[path] = name } } }
c24622
t.Imported[pkg.Path()] = pkg.Name() } }
c24623
Aliased import t.Aliased[path] = imported.Name.Name } } if path == "unsafe" { t.Imported[path] = path } } }
c24624
} } // try and resolve identity if ident, ok := arg.(*ast.Ident); ok { obj := c.Info.ObjectOf(ident) if _, ok := obj.(*types.Var); ok && !gosec.TryResolve(ident, c) { return true } } } } return false }
c24625
} } // handles binary string concatenation eg. ioutil.Readfile("/tmp/" + file + "/blob") if binExp, ok := arg.(*ast.BinaryExpr); ok { // resolve all found identities from the BinaryExpr if _, ok := gosec.FindVarIdentities(binExp, c); ok { return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r...
c24626
What: "Potential file inclusion via variable", Severity: gosec.Medium, Confidence: gosec.High, }, } rule.pathJoin.Add("path/filepath", "Join") rule.pathJoin.Add("path", "Join") rule.Add("io/ioutil", "ReadFile") rule.Add("os", "Open") return rule, []ast.Node{(*ast.CallExpr)(nil)} }
c24627
obj.(*types.Var); ok && !gosec.TryResolve(ident, c) { return true } } } return false }
c24628
What: "Potential HTTP request made with variable url", Severity: gosec.Medium, Confidence: gosec.Medium, }, } rule.AddAll("net/http", "Do", "Get", "Head", "Post", "PostForm", "RoundTrip") return rule, []ast.Node{(*ast.CallExpr)(nil)} }
c24629
c) case *ast.CallExpr: return resolveCallExpr(node, c) case *ast.BinaryExpr: return resolveBinExpr(node, c) } return false }
c24630
bug, should be int64 code, err = codeSnippet(file, s, e, node) if err != nil { code = err.Error() } } return &Issue{ File: name, Line: line, RuleID: ruleID, What: desc, Confidence: confidence, Severity: severity, Code: code, } }
c24631
} return &Analyzer{ ignoreNosec: ignoreNoSec, ruleset: make(RuleSet), context: &Context{}, config: conf, logger: logger, issues: make([]*Issue, 0, 16), stats: &Metrics{}, errors: make(map[string][]Error), tests: tests, } }
c24632
nodes := def(id, gosec.config) gosec.ruleset.Register(r, nodes...) } }
c24633
if err != nil { return fmt.Errorf("parsing errors in pkg %q: %v", pkg.Name, err) } gosec.check(pkg) } } } sortErrors(gosec.errors) return nil }
c24634
return fmt.Errorf("parsing column: %v", err) } } msg := strings.TrimSpace(pkgErr.Msg) newErr := NewError(line, column, msg) if errSlice, ok := gosec.errors[file]; ok { gosec.errors[file] = append(errSlice, *newErr) } else { errSlice = []Error{} gosec.errors[file] = append(errSlice, *newErr) ...
c24635
if ferrs, ok := gosec.errors[file]; ok { errors = ferrs } ferr := NewError(0, 0, err.Error()) errors = append(errors, *ferr) gosec.errors[file] = errors }
c24636
ignores[k] = v } } for _, v := range ignoredRules { ignores[v] = true } // Push the new set onto the stack. gosec.context.Ignores = append([]map[string]bool{ignores}, gosec.context.Ignores...) // Track aliased and initialization imports gosec.context.Imports.TrackImport(n) for _, rule := range gosec.ru...
c24637
gosec.issues, gosec.stats, gosec.errors }
c24638
gosec.issues = make([]*Issue, 0, 16) gosec.stats = &Metrics{} }
c24639
make(map[string]*Proxy) err = json.NewDecoder(resp.Body).Decode(&proxies) if err != nil { return nil, err } for _, proxy := range proxies { proxy.client = client proxy.created = true } return proxies, nil }
c24640
err } proxy := new(Proxy) err = json.NewDecoder(resp.Body).Decode(proxy) if err != nil { return nil, err } proxy.client = client proxy.created = true return proxy, nil }
c24641
var body bytes.Buffer tee := io.TeeReader(resp.Body, &body) err = json.NewDecoder(tee).Decode(&proxies) if err != nil { return nil, err } resp.Body = ioutil.NopCloser(&body) err = checkError(resp, http.StatusCreated, "Populate") return proxies.Proxies, err }
c24642
"application/json", bytes.NewReader(request)) } if err != nil { return err } if proxy.created { err = checkError(resp, http.StatusOK, "Save") } else { err = checkError(resp, http.StatusCreated, "Create") } if err != nil { return err } err = json.NewDecoder(resp.Body).Decode(proxy) if err != nil { ...
c24643
return nil, err } toxics := make(Toxics, 0) err = json.NewDecoder(resp.Body).Decode(&toxics) if err != nil { return nil, err } return toxics, nil }
c24644
return err } return checkError(resp, http.StatusNoContent, "ResetState") }
c24645
err := io.Copy(dest, link.output) if err != nil { logrus.WithFields(logrus.Fields{ "name": link.proxy.Name, "bytes": bytes, "err": err, }).Warn("Destination terminated") } dest.Close() link.toxics.RemoveLink(name) link.proxy.RemoveConnection(name) }() }
c24646
link.stubs[i-1].Output = newin if stateful, ok := toxic.Toxic.(toxics.StatefulToxic); ok { link.stubs[i].State = stateful.NewState() } go link.stubs[i].Run(toxic) go link.stubs[i-1].Run(link.toxics.chain[link.direction][i-1]) } else { // This link is already closed, make sure the new toxic matches ...
c24647
{ go link.stubs[toxic.Index].Run(toxic) } }
c24648
if !stopped { <-stop } return } link.stubs[i].Output <- tmp } } // Empty the toxic's buffer if necessary for len(link.stubs[i].Input) > 0 { tmp := <-link.stubs[i].Input if tmp == nil { link.stubs[i].Close() return } link.stubs[i].Output <- tmp } link.stubs[i...
c24649
defer close(s.running) if rand.Float32() < toxic.Toxicity { toxic.Pipe(s) } else { new(NoopToxic).Pipe(s) } }
c24650
// Wait for the running toxic to exit return true } }
c24651
the first noop toxic, it has no name continue } if toxic.Name == name { return toxic } } } return nil }
c24652
proxy.Name, "client": client.RemoteAddr(), "proxy": proxy.Listen, "upstream": proxy.Upstream, }).Info("Accepted client") upstream, err := net.Dial("tcp", proxy.Upstream) if err != nil { logrus.WithFields(logrus.Fields{ "name": proxy.Name, "client": client.RemoteAddr(), "proxy"...
c24653
err := <-proxy.started // Only enable the proxy if it successfully started proxy.Enabled = err == nil return err }
c24654
} logrus.WithFields(logrus.Fields{ "name": proxy.Name, "proxy": proxy.Listen, "upstream": proxy.Upstream, }).Info("Terminated proxy") }
c24655
Comments: parsePkgComment(f, f.Package), Package: f.Name.String(), Imports: parseImports(f.Imports), Code: goCode(b, f), }, Funcs: p.parseFunctions(fset, f, fs), }, nil }
c24656
Avoid wrong output on windows-encoded files if b[furthestPos-2] == '\r' && b[furthestPos-1] == '\n' && furthestPos < token.Pos(len(b)) { furthestPos++ } } return b[furthestPos:] }
c24657
return nil, fmt.Errorf("os.Stat: %v\n", err) } if fi.IsDir() { return dirFiles(srcPath) } return file(srcPath) }
c24658
} tmpls, err = tmpls.ParseFiles(templateFiles...) if err != nil { return fmt.Errorf("tmpls.ParseFiles: %v", err) } return nil }
c24659
= f.Close() return b, err } f, err := _escStatic.prepare(name) if err != nil { return nil, err } return f.data, nil }
c24660
b, err := FSByte(useLocal, name) if err != nil { panic(err) } return b }
c24661
err := FSByte(useLocal, name) return string(b), err }
c24662
string(FSMustByte(useLocal, name)) }
c24663
EventReader { return &parsedV4EventReader{ reader: reader, eventParsers: parsers, } }
c24664
errChan: make(chan error, 3), closed: false, }} go copyDataToOutput(toBeAdapted, &retval, output, shouldCloseDownstream) return &retval.Writer }
c24665
} rself.bufferToBeRead = *rself.workReceipt lenToCopy = len(rself.bufferToBeRead) } if lenToCopy > len(data) { lenToCopy = len(data) } copy(data[:lenToCopy], rself.bufferToBeRead[:lenToCopy]) rself.bufferToBeRead = rself.bufferToBeRead[lenToCopy:] if len(rself.bufferToBeRead) == 0 { rself.Writer.doneWo...
c24666
adaptedInput.Writer.errChan <- closeErr } } // pulls all the data from the writer until EOF is reached // this is because readers like zlib don't validate the CRC32 // (the last 4 bytes) in the normal codepath adaptedInput.drain() close(adaptedInput.Writer.errChan) }
c24667
options.DelFunc, delMulti: options.DelMultiFunc, errorOnFlush: options.ErrorOnFlush, flush: options.FlushFunc, } }
c24668
return nil } return s2.Copy() } s3 := s1.Copy() s3.Union(s2) return s3 }
c24669
{ return nil } return s2.New() } s3 := s1.Copy() s3.Intersect(s2) return s3 }
c24670
{ return nil } return s2.New() } s3 := s1.Copy() s3.Subtract(s2) return s3 }
c24671
return false } return s.IsSubset(s2) }
c24672
channel, validState: true, maxValueLength: defaultMaxValueLength, } }
c24673
channel, validState: true, maxValueLength: largeMaxValueLength, } }
c24674
nil")) } c.mutex.Lock() defer c.mutex.Unlock() if resp := c.sendMutateRequest(code, item, true); resp != nil { return resp } return c.receiveMutateResponse(code, item.Key) }
c24675
defer l.mutex.Unlock() return l.maxQuota }
c24676
q) } l.mutex.Lock() defer l.mutex.Unlock() l.maxQuota = q if l.quota > q { l.quota = q } if l.maxQuota == 0 { l.cond.Broadcast() } return nil }
c24677
defer l.mutex.Unlock() return l.quotaPerSec }
c24678
l.mutex.Lock() defer l.mutex.Unlock() l.quotaPerSec = r return nil }
c24679
defer l.mutex.Unlock() return l.quota }
c24680
defer l.mutex.Unlock() l.quota = q }
c24681
if l.stopped { return } l.stopped = true close(l.stopChan) l.ticker.Stop() l.cond.Broadcast() }
c24682
len(data) { // we need to overflow to remainder count, err := sbself.remainder.Write(data[toCopy:]) return count + toCopy, err } return toCopy, nil }
c24683
panic(err) } } amountReturned = sbself.userBufferCount sbself.userBuffer = nil sbself.userBufferCount = 0 return }
c24684
data []byte) { sbself.remainder.Reset() sbself.userBuffer = data sbself.userBufferCount = 0 }
c24685
:= rwaself.writer.(io.WriteCloser); ok { closeErr = writeCloser.Close() } } if err == nil && (writeErr != nil || closeErr != nil) { _ = rwaself.drain() // if there was an error with the writer, drain the upstream } if (err == nil || err == io.EOF) && writeErr != nil { err = writeErr } if (err ...
c24686
} else { rCloseErr = rwaself.drain() } if rCloseErr != nil && rCloseErr != io.EOF { return rCloseErr } if wCloseErr != nil && wCloseErr != io.EOF { return wCloseErr } return nil }
c24687
{ gzWriter, _ := gzip.NewWriterLevel(writer, compressionLevel) return gzipResponseWriter{ResponseWriter: writer, gzWriter: gzWriter} }
c24688
return f.performLock(syscall.LOCK_SH | syscall.LOCK_NB) }
c24689
f.performLock(syscall.LOCK_EX | syscall.LOCK_NB) }
c24690
} dc := &dateTimeColumn{} dc.name = name dc.nullable = nullable return dc }
c24691
} ic := &integerColumn{} ic.name = name ic.nullable = nullable return ic }
c24692
} ic := &doubleColumn{} ic.name = name ic.nullable = nullable return ic }
c24693
} bc := &booleanColumn{} bc.name = name bc.nullable = nullable return bc }
c24694
pool: pool, options: options, } atomic.StoreInt32(&h.isActive, 1) return h }
c24695
len(serverAddrs), len(serverAddrs)) for i, addr := range serverAddrs { shardStates[i].Address = addr shardStates[i].State = ActiveServer } manager.UpdateShardStates(shardStates) return manager }
c24696
{ return NewLookAheadBufferUsing(src, make([]byte, bufferSize, bufferSize)) }
c24697
return &LookAheadBuffer{ src: src, buffer: rawBuffer, bytesBuffered: 0, } }
c24698
if err != nil { // This should never happen panic(err) } }
c24699
{ if e.sqlMode == nil { return false } return (*e.sqlMode & (uint64(1) << uint(mode))) != 0 }