{"record":{"id":"a4951370ab4c0d41","repo":"go-delve/delve","slug":"regexp-compile-error-v","errorCode":null,"errorMessage":"regexp compile error: %v","messagePattern":"regexp compile error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/proc/native/proc_linux.go","lineNumber":284,"sourceCode":"\treturn 0, nil\n}\n\nfunc initialize(dbp *nativeProcess) (string, error) {\n\tcomm, err := os.ReadFile(fmt.Sprintf(\"/proc/%d/comm\", dbp.pid))\n\tif err == nil {\n\t\t// removes newline character\n\t\tcomm = bytes.TrimSuffix(comm, []byte(\"\\n\"))\n\t}\n\n\tif len(comm) <= 0 {\n\t\tstat, err := os.ReadFile(fmt.Sprintf(\"/proc/%d/stat\", dbp.pid))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"could not read proc stat: %v\", err)\n\t\t}\n\t\texpr := fmt.Sprintf(\"%d\\\\s*\\\\((.*)\\\\)\", dbp.pid)\n\t\trexp, err := regexp.Compile(expr)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"regexp compile error: %v\", err)\n\t\t}\n\t\tmatch := rexp.FindSubmatch(stat)\n\t\tif match == nil {\n\t\t\treturn \"\", fmt.Errorf(\"no match found using regexp '%s' in /proc/%d/stat\", expr, dbp.pid)\n\t\t}\n\t\tcomm = match[1]\n\t}\n\tdbp.os.comm = strings.ReplaceAll(string(comm), \"%\", \"%%\")\n\n\treturn getCmdLine(dbp.pid), nil\n}\n\nfunc (dbp *nativeProcess) GetBufferedTracepoints() []ebpf.RawUProbeParams {\n\tif dbp.os.ebpf == nil {\n\t\treturn nil\n\t}\n\treturn dbp.os.ebpf.GetBufferedTracepoints()\n}","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/proc_linux.go#L266-L302","documentation":"While extracting the process name from /proc/<pid>/stat, delve compiles the regexp \"<pid>\\\\s*\\\\((.*)\\\\)\". If regexp.Compile fails, this error is returned. Because the pattern is generated from an integer pid, compile failure is practically a defect or corrupted pid value rather than a user input problem.","triggerScenarios":"initialize's comm-extraction fallback builds the regexp from dbp.pid and regexp.Compile returns an error — in practice only possible with malformed pid input (negative/overflowing) since the base pattern is always valid Go regexp syntax.","commonSituations":"Effectively never hit by real users on Linux with valid pids; would surface from library misuse embedding a bogus pid, or from a modified delve source that interpolates unescaped user data into the expression.","solutions":["Verify the pid passed to attach is a positive valid int within platform range.","Update delve — with a stock build this error indicates a bug in the calling path.","If you patched the source, ensure interpolated values are integers and pattern metacharacters are escaped.","Capture the underlying regexp error message in the report (%v includes the syntax error position) to identify the malformed input."],"exampleFix":"// before\npid := someUserString // later attached after unchecked conversion\n\n// after\npid, err := strconv.Atoi(pidStr)\nif err != nil || pid <= 0 {\n    return fmt.Errorf(\"invalid pid %q\", pidStr)\n}","handlingStrategy":"validation","validationCode":"// validate pid input before any attach path\nfunc validPid(p int) bool { return p > 0 && p <= 1<<31-1 }","typeGuard":null,"tryCatchPattern":"err := debugger.Attach(pid, nil)\nif err != nil && strings.Contains(err.Error(), \"regexp compile error\") {\n    return fmt.Errorf(\"internal error or bad pid %d: %w\", pid, err)\n}","preventionTips":["Always pass positive integer pids from validated input.","On a stock delve build this error signals a bug — report it with the underlying regexp message.","If patching delve, never interpolate unescaped user strings into patterns."],"tags":["linux","regexp","procfs","input-validation"],"backgroundTag":"regexp-compile-error","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}