{"record":{"id":"7313f0b39e12fa8f","repo":"ginuerzh/gost","slug":"s-v-7313f0","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tuntap_linux.go","lineNumber":153,"sourceCode":"\t\t\tcontinue\n\t\t}\n\t\tcmd := fmt.Sprintf(\"ip route add %s via %s dev %s\", route, gw, ifName)\n\t\tlog.Logf(\"[tap] %s\", cmd)\n\n\t\targs := strings.Split(cmd, \" \")\n\t\tif er := exec.Command(args[0], args[1:]...).Run(); er != nil {\n\t\t\tlog.Logf(\"[tap] %s: %v\", cmd, er)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc exeCmd(cmd string) error {\n\tlog.Log(cmd)\n\n\targs := strings.Split(cmd, \" \")\n\tif err := exec.Command(args[0], args[1:]...).Run(); err != nil {\n\t\treturn fmt.Errorf(\"%s: %v\", cmd, err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":135,"sourceCodeEnd":158,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/tuntap_linux.go#L135-L158","documentation":"exeCmd runs a shell command built as a single string (split on spaces) and wraps any non-zero exit or spawn failure with the full command line and the underlying error. This library (tuntap) configures TUN/TAP interfaces by shelling out to system tools, so any failure of those tools surfaces as this wrapped error.","triggerScenarios":"exeCmd is called from createTun/createTap with a malformed command string, a missing binary (exec: \"ip\": executable file not found), or the command exits non-zero (e.g. permission denied configuring the interface).","commonSituations":"Running without root/CAP_NET_ADMIN; the required tool (e.g. `ip`) not installed on the Linux image (slim containers); interface name or CIDR containing characters that break the naive strings.Split(cmd, \" \") parsing.","solutions":["Run the program as root or with CAP_NET_ADMIN so the networking command can succeed","Install the required networking tool (iproute2) in the environment/container","Check the wrapped %v message: 'executable file not found' means the tool is missing, 'operation not permitted' means insufficient privileges","Print cfg values (Addr, MTU, Routes) to confirm no malformed input produced a broken command string"],"exampleFix":"// before\nif err := exeCmd(\"ip addr add 10.0.0.1/24 dev tun0\"); err != nil { ... } // run as non-root fails\n// after\n// run binary as root: sudo ./app  (or grant: setcap cap_net_admin+ep ./app)","handlingStrategy":"validation","validationCode":"func canConfigureNet() error {\n    if os.Geteuid() != 0 {\n        return errors.New(\"tuntap: needs root/CAP_NET_ADMIN\")\n    }\n    if _, err := exec.LookPath(\"ip\"); err != nil {\n        return fmt.Errorf(\"tuntap: iproute2 missing: %w\", err)\n    }\n    return nil\n}","typeGuard":"func cmdToolExists(name string) bool { _, err := exec.LookPath(name); return err == nil }","tryCatchPattern":"if err := tun.CreateTun(cfg); err != nil {\n    var ee *exec.ExitError\n    if errors.As(err, &ee) {\n        log.Printf(\"netsetup failed: %s; stderr: %s\", err, ee.Stderr)\n    }\n    if strings.Contains(err.Error(), \"not found\") { /* install tool */ }\n    if strings.Contains(err.Error(), \"operation not permitted\") { /* request privileges */ }\n}","preventionTips":["Run the binary as root or grant cap_net_admin via setcap","Ensure iproute2 (or the target tool) is present in your container image","Never embed spaces-in-values in the command string; the library splits on spaces","Log cfg fields before calling createTun/createTap to catch malformed input"],"tags":["exec","command-failed","tuntap","privileges"],"backgroundTag":"command-execution-failed","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}