main.go 1005 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. "os/exec"
  7. "sync"
  8. )
  9. const (
  10. SYSCALL_NUMS = 400
  11. )
  12. func main() {
  13. // copy ./internal/core/runner/python/python.so to /tmp/sandbox-python/python.so
  14. os.MkdirAll("/tmp/sandbox-python", 0755)
  15. f1, err := os.Create("/tmp/sandbox-python/python.so")
  16. if err != nil {
  17. fmt.Println(err)
  18. return
  19. }
  20. f2, err := os.Open("./internal/core/runner/python/python.so")
  21. if err != nil {
  22. fmt.Println(err)
  23. return
  24. }
  25. io.Copy(f1, f2)
  26. f1.Close()
  27. f2.Close()
  28. for i := 0; i < SYSCALL_NUMS; i++ {
  29. os.Setenv("DISABLE_SYSCALL", fmt.Sprintf("%d", i))
  30. var err error
  31. var jobs = make(chan int, 100)
  32. var wg sync.WaitGroup
  33. for j := 0; j < 4; j++ {
  34. wg.Add(1)
  35. i := i
  36. go func() {
  37. defer wg.Done()
  38. for range jobs {
  39. if err != nil {
  40. continue
  41. }
  42. _, err = exec.Command("python3", ".fuzz.py").Output()
  43. if err != nil {
  44. fmt.Println(i)
  45. }
  46. }
  47. }()
  48. }
  49. for j := 0; j < 100; j++ {
  50. jobs <- j
  51. }
  52. close(jobs)
  53. wg.Wait()
  54. }
  55. }