How to use saveFailedRepro method of main Package

Best Syzkaller code snippet using main.saveFailedRepro

manager.go

Source:manager.go Github

copy

Full Screen

...405 instances = append(instances, res.instances...)406 reproInstances -= instancesPerRepro407 if res.res == nil {408 if !res.hub {409 mgr.saveFailedRepro(res.report0, res.stats)410 }411 } else {412 mgr.saveRepro(res.res, res.stats, res.hub)413 }414 case <-shutdown:415 log.Logf(1, "loop: shutting down...")416 shutdown = nil417 case crash := <-mgr.hubReproQueue:418 log.Logf(1, "loop: get repro from hub")419 pendingRepro[crash] = true420 case reply := <-mgr.needMoreRepros:421 reply <- phase >= phaseTriagedHub &&422 len(reproQueue)+len(pendingRepro)+len(reproducing) == 0423 goto wait424 case reply := <-mgr.reproRequest:425 repros := make(map[string]bool)426 for title := range reproducing {427 repros[title] = true428 }429 reply <- repros430 goto wait431 }432 }433}434func (mgr *Manager) loadCorpus() {435 // By default we don't re-minimize/re-smash programs from corpus,436 // it takes lots of time on start and is unnecessary.437 // However, on version bumps we can selectively re-minimize/re-smash.438 minimized, smashed := true, true439 switch mgr.corpusDB.Version {440 case 0:441 // Version 0 had broken minimization, so we need to re-minimize.442 minimized = false443 fallthrough444 case 1:445 // Version 1->2: memory is preallocated so lots of mmaps become unnecessary.446 minimized = false447 fallthrough448 case 2:449 // Version 2->3: big-endian hints.450 smashed = false451 fallthrough452 case 3:453 // Version 3->4: to shake things up.454 minimized = false455 fallthrough456 case currentDBVersion:457 }458 broken := 0459 for key, rec := range mgr.corpusDB.Records {460 bad, disabled := checkProgram(mgr.target, mgr.targetEnabledSyscalls, rec.Val)461 if bad {462 mgr.corpusDB.Delete(key)463 broken++464 continue465 }466 if disabled {467 // This program contains a disabled syscall.468 // We won't execute it, but remember its hash so469 // it is not deleted during minimization.470 mgr.disabledHashes[hash.String(rec.Val)] = struct{}{}471 continue472 }473 mgr.candidates = append(mgr.candidates, rpctype.RPCCandidate{474 Prog: rec.Val,475 Minimized: minimized,476 Smashed: smashed,477 })478 }479 mgr.fresh = len(mgr.corpusDB.Records) == 0480 log.Logf(0, "%-24v: %v",481 "corpus", len(mgr.candidates))482 // Now this is ugly.483 // We duplicate all inputs in the corpus and shuffle the second part.484 // This solves the following problem. A fuzzer can crash while triaging candidates,485 // in such case it will also lost all cached candidates. Or, the input can be somewhat flaky486 // and doesn't give the coverage on first try. So we give each input the second chance.487 // Shuffling should alleviate deterministically losing the same inputs on fuzzer crashing.488 mgr.candidates = append(mgr.candidates, mgr.candidates...)489 shuffle := mgr.candidates[len(mgr.candidates)/2:]490 rand.Shuffle(len(shuffle), func(i, j int) {491 shuffle[i], shuffle[j] = shuffle[j], shuffle[i]492 })493 if mgr.phase != phaseInit {494 panic(fmt.Sprintf("loadCorpus: bad phase %v", mgr.phase))495 }496 mgr.phase = phaseLoadedCorpus497}498func checkProgram(target *prog.Target, enabled map[*prog.Syscall]bool, data []byte) (bad, disabled bool) {499 p, err := target.Deserialize(data, prog.NonStrict)500 if err != nil {501 return true, true502 }503 if len(p.Calls) > prog.MaxCalls {504 return true, true505 }506 for _, c := range p.Calls {507 if !enabled[c.Meta] {508 return false, true509 }510 }511 return false, false512}513func (mgr *Manager) runInstance(index int) (*Crash, error) {514 mgr.checkUsedFiles()515 inst, err := mgr.vmPool.Create(index)516 if err != nil {517 return nil, fmt.Errorf("failed to create instance: %v", err)518 }519 defer inst.Close()520 fwdAddr, err := inst.Forward(mgr.port)521 if err != nil {522 return nil, fmt.Errorf("failed to setup port forwarding: %v", err)523 }524 fuzzerBin, err := inst.Copy(mgr.cfg.SyzFuzzerBin)525 if err != nil {526 return nil, fmt.Errorf("failed to copy binary: %v", err)527 }528 // If SyzExecutorCmd is provided, it means that syz-executor is already in529 // the image, so no need to copy it.530 executorCmd := targets.Get(mgr.cfg.TargetOS, mgr.cfg.TargetArch).SyzExecutorCmd531 if executorCmd == "" {532 executorCmd, err = inst.Copy(mgr.cfg.SyzExecutorBin)533 if err != nil {534 return nil, fmt.Errorf("failed to copy binary: %v", err)535 }536 }537 fuzzerV := 0538 procs := mgr.cfg.Procs539 if *flagDebug {540 fuzzerV = 100541 procs = 1542 }543 // Run the fuzzer binary.544 start := time.Now()545 atomic.AddUint32(&mgr.numFuzzing, 1)546 defer atomic.AddUint32(&mgr.numFuzzing, ^uint32(0))547 cmd := instance.FuzzerCmd(fuzzerBin, executorCmd, fmt.Sprintf("vm-%v", index),548 mgr.cfg.TargetOS, mgr.cfg.TargetArch, fwdAddr, mgr.cfg.Sandbox, procs, fuzzerV,549 mgr.cfg.Cover, *flagDebug, false, false)550 outc, errc, err := inst.Run(time.Hour, mgr.vmStop, cmd)551 if err != nil {552 return nil, fmt.Errorf("failed to run fuzzer: %v", err)553 }554 rep := inst.MonitorExecution(outc, errc, mgr.reporter, vm.ExitTimeout)555 if rep == nil {556 // This is the only "OK" outcome.557 log.Logf(0, "vm-%v: running for %v, restarting", index, time.Since(start))558 return nil, nil559 }560 crash := &Crash{561 vmIndex: index,562 hub: false,563 Report: rep,564 }565 return crash, nil566}567func (mgr *Manager) emailCrash(crash *Crash) {568 if len(mgr.cfg.EmailAddrs) == 0 {569 return570 }571 args := []string{"-s", "syzkaller: " + crash.Title}572 args = append(args, mgr.cfg.EmailAddrs...)573 log.Logf(0, "sending email to %v", mgr.cfg.EmailAddrs)574 cmd := exec.Command("mailx", args...)575 cmd.Stdin = bytes.NewReader(crash.Report.Report)576 if _, err := osutil.Run(10*time.Minute, cmd); err != nil {577 log.Logf(0, "failed to send email: %v", err)578 }579}580func (mgr *Manager) saveCrash(crash *Crash) bool {581 if crash.Type == report.MemoryLeak {582 mgr.mu.Lock()583 mgr.memoryLeakFrames[crash.Frame] = true584 mgr.mu.Unlock()585 }586 if crash.Type == report.DataRace {587 mgr.mu.Lock()588 mgr.dataRaceFrames[crash.Frame] = true589 mgr.mu.Unlock()590 }591 if crash.Suppressed {592 log.Logf(0, "vm-%v: suppressed crash %v", crash.vmIndex, crash.Title)593 mgr.stats.crashSuppressed.inc()594 return false595 }596 corrupted := ""597 if crash.Corrupted {598 corrupted = " [corrupted]"599 }600 log.Logf(0, "vm-%v: crash: %v%v", crash.vmIndex, crash.Title, corrupted)601 if err := mgr.reporter.Symbolize(crash.Report); err != nil {602 log.Logf(0, "failed to symbolize report: %v", err)603 }604 mgr.stats.crashes.inc()605 mgr.mu.Lock()606 if !mgr.crashTypes[crash.Title] {607 mgr.crashTypes[crash.Title] = true608 mgr.stats.crashTypes.inc()609 }610 mgr.mu.Unlock()611 if mgr.dash != nil {612 if crash.Type == report.MemoryLeak {613 return true614 }615 dc := &dashapi.Crash{616 BuildID: mgr.cfg.Tag,617 Title: crash.Title,618 Corrupted: crash.Corrupted,619 Maintainers: crash.Maintainers,620 Log: crash.Output,621 Report: crash.Report.Report,622 }623 resp, err := mgr.dash.ReportCrash(dc)624 if err != nil {625 log.Logf(0, "failed to report crash to dashboard: %v", err)626 } else {627 // Don't store the crash locally, if we've successfully628 // uploaded it to the dashboard. These will just eat disk space.629 return resp.NeedRepro630 }631 }632 sig := hash.Hash([]byte(crash.Title))633 id := sig.String()634 dir := filepath.Join(mgr.crashdir, id)635 osutil.MkdirAll(dir)636 if err := osutil.WriteFile(filepath.Join(dir, "description"), []byte(crash.Title+"\n")); err != nil {637 log.Logf(0, "failed to write crash: %v", err)638 }639 // Save up to 100 reports. If we already have 100, overwrite the oldest one.640 // Newer reports are generally more useful. Overwriting is also needed641 // to be able to understand if a particular bug still happens or already fixed.642 oldestI := 0643 var oldestTime time.Time644 for i := 0; i < 100; i++ {645 info, err := os.Stat(filepath.Join(dir, fmt.Sprintf("log%v", i)))646 if err != nil {647 oldestI = i648 if i == 0 {649 go mgr.emailCrash(crash)650 }651 break652 }653 if oldestTime.IsZero() || info.ModTime().Before(oldestTime) {654 oldestI = i655 oldestTime = info.ModTime()656 }657 }658 osutil.WriteFile(filepath.Join(dir, fmt.Sprintf("log%v", oldestI)), crash.Output)659 if len(mgr.cfg.Tag) > 0 {660 osutil.WriteFile(filepath.Join(dir, fmt.Sprintf("tag%v", oldestI)), []byte(mgr.cfg.Tag))661 }662 if len(crash.Report.Report) > 0 {663 osutil.WriteFile(filepath.Join(dir, fmt.Sprintf("report%v", oldestI)), crash.Report.Report)664 }665 return mgr.needLocalRepro(crash)666}667const maxReproAttempts = 3668func (mgr *Manager) needLocalRepro(crash *Crash) bool {669 if !mgr.cfg.Reproduce || crash.Corrupted {670 return false671 }672 if mgr.checkResult == nil || (mgr.checkResult.Features[host.FeatureLeak].Enabled &&673 crash.Type != report.MemoryLeak) {674 // Leak checking is very slow, don't bother reproducing other crashes.675 return false676 }677 sig := hash.Hash([]byte(crash.Title))678 dir := filepath.Join(mgr.crashdir, sig.String())679 if osutil.IsExist(filepath.Join(dir, "repro.prog")) {680 return false681 }682 for i := 0; i < maxReproAttempts; i++ {683 if !osutil.IsExist(filepath.Join(dir, fmt.Sprintf("repro%v", i))) {684 return true685 }686 }687 return false688}689func (mgr *Manager) needRepro(crash *Crash) bool {690 if crash.hub {691 return true692 }693 if mgr.dash == nil {694 return mgr.needLocalRepro(crash)695 }696 if crash.Type == report.MemoryLeak {697 return true698 }699 cid := &dashapi.CrashID{700 BuildID: mgr.cfg.Tag,701 Title: crash.Title,702 Corrupted: crash.Corrupted,703 }704 needRepro, err := mgr.dash.NeedRepro(cid)705 if err != nil {706 log.Logf(0, "dashboard.NeedRepro failed: %v", err)707 }708 return needRepro709}710func (mgr *Manager) saveFailedRepro(rep *report.Report, stats *repro.Stats) {711 if rep.Type == report.MemoryLeak {712 // Don't send failed leak repro attempts to dashboard713 // as we did not send the crash itself.714 return715 }716 if mgr.dash != nil {717 cid := &dashapi.CrashID{718 BuildID: mgr.cfg.Tag,719 Title: rep.Title,720 }721 if err := mgr.dash.ReportFailedRepro(cid); err != nil {722 log.Logf(0, "failed to report failed repro to dashboard: %v", err)723 } else {724 return...

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Create("test.txt")4 if err != nil {5 fmt.Println(err)6 }7 defer f.Close()8}9import (10func main() {11 f, err := os.Create("test.txt")12 if err != nil {13 fmt.Println(err)14 }15 defer f.Close()16}17import (18func main() {19 f, err := os.Create("test.txt")20 if err != nil {21 fmt.Println(err)22 }23 defer f.Close()24}25import (26func main() {27 f, err := os.Create("test.txt")28 if err != nil {29 fmt.Println(err)30 }31 defer f.Close()32}33import (34func main() {35 f, err := os.Create("test.txt")36 if err != nil {37 fmt.Println(err)38 }39 defer f.Close()40}41import (42func main() {43 f, err := os.Create("test.txt")44 if err != nil {45 fmt.Println(err)46 }47 defer f.Close()48}49import (50func main() {51 f, err := os.Create("test.txt")52 if err != nil {53 fmt.Println(err)54 }55 defer f.Close()56}57import (58func main() {59 f, err := os.Create("test.txt")60 if err != nil {61 fmt.Println(err)

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 saveFailedRepro("sample.txt")5}6import (7func main() {8 fmt.Println("Hello, playground")9 saveFailedRepro("sample.txt")10}11import (12func main() {13 fmt.Println("Hello, playground")14 saveFailedRepro("sample.txt")15}16import (17func main() {18 fmt.Println("Hello, playground")19 saveFailedRepro("sample.txt")20}21import (22func main() {23 fmt.Println("Hello, playground")24 saveFailedRepro("sample.txt")25}26import (27func main() {28 fmt.Println("Hello, playground")29 saveFailedRepro("sample.txt")30}31import (32func main() {33 fmt.Println("Hello, playground")34 saveFailedRepro("sample.txt")35}36import (37func main() {38 fmt.Println("Hello, playground")39 saveFailedRepro("sample.txt")40}41import (42func main() {43 fmt.Println("Hello, playground")44 saveFailedRepro("sample.txt")45}46import (47func main() {48 fmt.Println("Hello, playground")49 saveFailedRepro("sample.txt

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("hello, world")4 main.saveFailedRepro()5}6import (7func main() {8 fmt.Println("hello, world")9 main.saveFailedRepro()10}11import "fmt"12type Main struct {13}14func (m *Main) SaveFailedRepro() {15 fmt.Println("SaveFailedRepro")16}17func main() {18 m := &Main{Name: "foo"}19 m.SaveFailedRepro()20}

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 debug.SetTraceback("all")4 runtime.SetBlockProfileRate(1)5 runtime.SetMutexProfileFraction(1)6 runtime.SetCPUProfileRate(1)7 go func() {8 for {9 }10 }()11 go func() {12 for {13 runtime.GC()14 runtime.Gosched()15 }16 }()17 go func() {18 for {19 runtime.GC()20 runtime.Gosched()21 }22 }()23 go func() {24 for {25 runtime.GC()26 runtime.Gosched()27 }28 }()29 go func() {30 for {31 runtime.GC()32 runtime.Gosched()33 }34 }()35 go func() {36 for {37 runtime.GC()38 runtime.Gosched()39 }40 }()41 go func() {42 for {43 runtime.GC()44 runtime.Gosched()45 }46 }()47 go func() {48 for {49 runtime.GC()50 runtime.Gosched()51 }52 }()53 go func() {54 for {55 runtime.GC()56 runtime.Gosched()57 }58 }()59 go func() {60 for {61 runtime.GC()62 runtime.Gosched()63 }64 }()65 go func() {66 for {67 runtime.GC()68 runtime.Gosched()69 }70 }()71 go func() {72 for {73 runtime.GC()74 runtime.Gosched()75 }76 }()77 go func() {78 for {79 runtime.GC()80 runtime.Gosched()81 }82 }()83 go func() {84 for {85 runtime.GC()86 runtime.Gosched()87 }88 }()89 go func() {90 for {91 runtime.GC()92 runtime.Gosched()93 }94 }()95 go func() {96 for {97 runtime.GC()98 runtime.Gosched()99 }100 }()101 go func() {102 for {103 runtime.GC()104 runtime.Gosched()

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import java.io.*;2import java.util.*;3import java.util.regex.*;4import java.util.concurrent.*;5import java.util.concurrent.atomic.*;6import java.util.concurrent.locks.*;7import java.util.concurrent.locks.ReentrantLock;8import java.io.*;9import java.util.*;10import java.util.regex.*;11import java.util.concurrent.*;12import java.util.concurrent.atomic.*;13import java.util.concurrent.locks.*;14import java.util.concurrent.locks.ReentrantLock;15import java.io.*;16import java.util.*;17import java.util.regex.*;18import java.util.concurrent.*;19import java.util.concurrent.atomic.*;20import java.util.concurrent.locks.*;21import java.util.concurrent.locks.ReentrantLock;22import java.io.*;23import java.util.*;24import java.util.regex.*;25import java.util.concurrent.*;26import java.util.concurrent.atomic.*;27import java.util.concurrent.locks.*;28import java.util.concurrent.locks.ReentrantLock;29import java.io.*;30import java.util.*;31import java.util.regex.*;32import java.util.concurrent.*;33import java.util.concurrent.atomic.*;34import java.util.concurrent.locks.*;35import java.util.concurrent.locks.ReentrantLock;36import java.io.*;37import java.util.*;38import java.util.regex.*;39import java.util.concurrent.*;40import java.util.concurrent.atomic.*;41import java.util.concurrent.locks.*;42import java.util.concurrent.locks.ReentrantLock;43import java.io.*;44import java.util.*;45import java.util.regex.*;46import java.util.concurrent.*;47import java.util.concurrent.atomic.*;48import java.util.concurrent.locks.*;49import java.util.concurrent.locks.ReentrantLock;50import java.io.*;51import java.util.*;52import java.util.regex.*;53import java.util.concurrent.*;54import java.util.concurrent.atomic.*;55import java.util.concurrent.locks.*;56import java.util.concurrent.locks.ReentrantLock;57import java.io.*;58import java.util.*;59import java.util.regex.*;60import java.util.concurrent.*;61import java.util.concurrent.atomic.*;62import java.util.concurrent.locks.*;63import java.util.concurrent.locks.ReentrantLock;64import java.io.*;65import java.util.*;66import java.util.regex.*;67import java.util.concurrent.*;68import java.util.concurrent.atomic.*;69import java.util.concurrent.locks.*;70import java.util.concurrent.locks.ReentrantLock;71import java.io.*;72import java.util.*;73import java.util.regex.*;74import java.util.concurrent.*;75import java.util.concurrent.atomic.*;76import java.util.concurrent.locks.*;77import java.util.concurrent.locks.ReentrantLock;78import java.io.*;79import java.util.*;80import java.util.regex.*;81import java.util.concurrent.*;82import java.util.concurrent.atomic.*;83import java.util.concurrent.locks.*;84import java.util.concurrent.locks.ReentrantLock;85import java.io.*;86import java

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, err := os.Create("newFile.txt")4 if err != nil {5 fmt.Println("Error creating file:", err)6 }7 defer file.Close()8 fmt.Fprintf(file, "Hello World")9 file, err = os.Open("newFile.txt")10 if err != nil {11 fmt.Println("Error opening file:", err)12 }13 defer file.Close()14 scanner := bufio.NewScanner(file)15 for scanner.Scan() {16 fmt.Println(scanner.Text())17 }18 if err := scanner.Err(); err != nil {19 fmt.Println("Error scanning file:", err)20 }21}22import (23func main() {24 jsonFile, err := os.Open("newFile.txt")25 if err != nil {26 fmt.Println(err)27 }28 fmt.Println("Successfully Opened users.json")29 defer jsonFile.Close()30 byteValue, _ := ioutil.ReadAll(jsonFile)31 json.Unmarshal(byteValue, &users)32 for i := 0; i < len(users.Users); i++ {33 fmt.Println("User Type: " + users.Users[i].Type)34 fmt.Println("Name: " + users.Users[i].Name)35 fmt.Println("Url: " + users.Users[i].Url)36 fmt.Println("")37 }38 f, err := os.Open("newFile.txt")39 if err != nil {40 log.Fatal(err)

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter the name of the file to be saved")4 fmt.Scanln(&name)5 fmt.Println("Enter the path of the file to be saved")6 fmt.Scanln(&path)7 fmt.Println("Enter the contents of the file to be saved")8 fmt.Scanln(&contents)9 saveFailedRepro(name, path, contents)10}11func saveFailedRepro(name, path, contents string) {12 file, err := os.Create(path + "/" + name)13 if err != nil {14 fmt.Println(err)15 }16 defer file.Close()17 _, err = file.WriteString(contents)18 if err != nil {19 fmt.Println(err)20 file.Close()21 }22 err = file.Close()23 if err != nil {24 fmt.Println(err)25 }26 file, err = os.Open(path + "/" + name)27 if err != nil {28 fmt.Println(err)29 }30 defer file.Close()31 fileContents, err := exec.Command("cat", path+"/"+name).Output()32 if err != nil {33 fmt.Println(err)34 }35 fmt.Println(string(fileContents))36}37Go to the next page: Go: File Handling (2)

Full Screen

Full Screen

saveFailedRepro

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 saveFailedRepro("test.txt")4}5import (6func main() {7 saveFailedRepro("test.txt")8}9import (10func main() {11 saveFailedRepro("test.txt")12}13import (14func main() {15 saveFailedRepro("test.txt")16}17import (18func main() {19 saveFailedRepro("test.txt")20}21import (22func main() {23 saveFailedRepro("test.txt")24}25import (26func main() {27 saveFailedRepro("test.txt")28}29import (30func main() {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful