main.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "os/exec"
  6. "strconv"
  7. "strings"
  8. "sync"
  9. "github.com/langgenius/dify-sandbox/internal/static/python_syscall"
  10. )
  11. const (
  12. SYSCALL_NUMS = 400
  13. )
  14. func run(allowed_syscalls []int) {
  15. nums := []string{}
  16. for _, syscall := range allowed_syscalls {
  17. nums = append(nums, strconv.Itoa(syscall))
  18. }
  19. os.Setenv("ALLOWED_SYSCALLS", strings.Join(nums, ","))
  20. _, err := exec.Command("python3", "cmd/test/fuzz_python_amd64/test.py").Output()
  21. if err == nil {
  22. } else {
  23. fmt.Println("failed")
  24. }
  25. }
  26. func find_syscall(syscall int, syscalls []int) int {
  27. for i, s := range syscalls {
  28. if s == syscall {
  29. return i
  30. }
  31. }
  32. return -1
  33. }
  34. func main() {
  35. original := python_syscall.ALLOW_SYSCALLS
  36. original = append(original, python_syscall.ALLOW_NETWORK_SYSCALLS...)
  37. // generate task list
  38. list := make([][]int, SYSCALL_NUMS)
  39. for i := 0; i < SYSCALL_NUMS; i++ {
  40. list[i] = make([]int, len(original))
  41. copy(list[i], original)
  42. // add i
  43. if find_syscall(i, original) == -1 {
  44. list[i] = append(list[i], i)
  45. }
  46. // for j := 217; j < 218; j++ {
  47. // if find_syscall(j, list[i]) == -1 {
  48. // list[i] = append(list[i], j)
  49. // }
  50. // }
  51. }
  52. lock := sync.Mutex{}
  53. wg := sync.WaitGroup{}
  54. i := 0
  55. // run 4 tasks concurrently
  56. for j := 0; j < 4; j++ {
  57. wg.Add(1)
  58. go func() {
  59. defer wg.Done()
  60. for {
  61. lock.Lock()
  62. if i >= len(list) {
  63. lock.Unlock()
  64. return
  65. }
  66. task := list[i]
  67. i++
  68. lock.Unlock()
  69. run(task)
  70. }
  71. }()
  72. }
  73. // wait for all tasks to finish
  74. wg.Wait()
  75. }