{"record":{"id":"d91d4347f0067cf1","repo":"openai/codex","slug":"failed-to-convert-arg-to-cstring","errorCode":null,"errorMessage":"Failed to convert arg to CString","messagePattern":"Failed to convert arg to CString","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"codex-rs/linux-sandbox/src/linux_run_main.rs","lineNumber":1566,"sourceCode":"        let proxy_route_spec = proxy_route_spec\n            .unwrap_or_else(|| panic!(\"managed proxy mode requires a proxy route spec\"));\n        inner.push(\"--proxy-route-spec\".to_string());\n        inner.push(proxy_route_spec);\n    }\n    inner.push(\"--\".to_string());\n    inner.extend(command);\n    inner\n}\n\n/// Exec the provided argv, panicking with context if it fails.\nfn exec_or_panic(command: Vec<String>) -> ! {\n    #[expect(clippy::expect_used)]\n    let c_command =\n        CString::new(command[0].as_str()).expect(\"Failed to convert command to CString\");\n    #[expect(clippy::expect_used)]\n    let c_args: Vec<CString> = command\n        .iter()\n        .map(|arg| CString::new(arg.as_str()).expect(\"Failed to convert arg to CString\"))\n        .collect();\n\n    let mut c_args_ptrs: Vec<*const libc::c_char> = c_args.iter().map(|arg| arg.as_ptr()).collect();\n    c_args_ptrs.push(std::ptr::null());\n\n    unsafe {\n        libc::execvp(c_command.as_ptr(), c_args_ptrs.as_ptr());\n    }\n\n    // If execvp returns, there was an error.\n    let err = std::io::Error::last_os_error();\n    panic!(\"Failed to execvp {}: {err}\", command[0].as_str());\n}\n\n#[cfg(test)]\n#[path = \"linux_run_main_tests.rs\"]\nmod tests;\n","sourceCodeStart":1548,"sourceCodeEnd":1584,"githubUrl":"https://github.com/openai/codex/blob/339751715c64496cb86246bfb3935f40e309dd3d/codex-rs/linux-sandbox/src/linux_run_main.rs#L1548-L1584","documentation":"A command argument intended for execvp contained an interior NUL byte and could not be converted to a C string. This guard in exec_or_panic fires on CString::new failure for one of the argv entries; on Linux real paths cannot contain NUL, so this indicates corrupted or programmatically-mangled argument data rather than user input.","triggerScenarios":"Thrown at codex-rs/linux-sandbox/src/linux_run_main.rs:1566 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the command vector for arguments containing NUL or invalid content","Fix the code path that constructed the argv entry (encoding bug, truncation)","Sanitize programmatically generated arguments before launching the sandbox"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"339751715c64496cb86246bfb3935f40e309dd3d","analyzedAt":"2026-08-25T05:35:09.876Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}