(
path: OsPath,
argv: Either<PyListRef, PyTupleRef>,
env: ArgMapping,
vm: &VirtualMachine,
)
| 1317 | |
| 1318 | #[pyfunction] |
| 1319 | fn execve( |
| 1320 | path: OsPath, |
| 1321 | argv: Either<PyListRef, PyTupleRef>, |
| 1322 | env: ArgMapping, |
| 1323 | vm: &VirtualMachine, |
| 1324 | ) -> PyResult<()> { |
| 1325 | let path = path.into_cstring(vm)?; |
| 1326 | |
| 1327 | let argv = vm.extract_elements_with(argv.as_ref(), |obj| { |
| 1328 | OsPath::try_from_object(vm, obj)?.into_cstring(vm) |
| 1329 | })?; |
| 1330 | let argv: Vec<&CStr> = argv.iter().map(|entry| entry.as_c_str()).collect(); |
| 1331 | |
| 1332 | let first = argv |
| 1333 | .first() |
| 1334 | .ok_or_else(|| vm.new_value_error("execve() arg 2 must not be empty"))?; |
| 1335 | |
| 1336 | if first.to_bytes().is_empty() { |
| 1337 | return Err(vm.new_value_error("execve() arg 2 first element cannot be empty")); |
| 1338 | } |
| 1339 | |
| 1340 | let env = crate::stdlib::os::envobj_to_dict(env, vm)?; |
| 1341 | let env = env |
| 1342 | .into_iter() |
| 1343 | .map(|(k, v)| -> PyResult<_> { |
| 1344 | let (key, value) = ( |
| 1345 | OsPath::try_from_object(vm, k)?.into_bytes(), |
| 1346 | OsPath::try_from_object(vm, v)?.into_bytes(), |
| 1347 | ); |
| 1348 | |
| 1349 | if key.is_empty() || memchr::memchr(b'=', &key).is_some() { |
| 1350 | return Err(vm.new_value_error("illegal environment variable name")); |
| 1351 | } |
| 1352 | |
| 1353 | let mut entry = key; |
| 1354 | entry.push(b'='); |
| 1355 | entry.extend_from_slice(&value); |
| 1356 | |
| 1357 | CString::new(entry).map_err(|err| err.into_pyexception(vm)) |
| 1358 | }) |
| 1359 | .collect::<Result<Vec<_>, _>>()?; |
| 1360 | |
| 1361 | let env: Vec<&CStr> = env.iter().map(|entry| entry.as_c_str()).collect(); |
| 1362 | |
| 1363 | unistd::execve(&path, &argv, &env).map_err(|err| err.into_pyexception(vm))?; |
| 1364 | Ok(()) |
| 1365 | } |
| 1366 | |
| 1367 | #[pyfunction] |
| 1368 | fn getppid(vm: &VirtualMachine) -> PyObjectRef { |
nothing calls this directly
no test coverage detected