Skip to content

Commit 8fdc4db

Browse files
committed
Fix: check name contain null
1 parent 098a709 commit 8fdc4db

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

vm/src/stdlib/pwd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod pwd {
55
use crate::{
66
builtins::{PyIntRef, PyStrRef},
77
convert::{IntoPyException, ToPyObject},
8+
exceptions,
89
types::PyStructSequence,
910
AsObject, PyObjectRef, PyResult, VirtualMachine,
1011
};
@@ -52,6 +53,9 @@ mod pwd {
5253

5354
#[pyfunction]
5455
fn getpwnam(name: PyStrRef, vm: &VirtualMachine) -> PyResult<Passwd> {
56+
if name.as_str().contains('\0') {
57+
return Err(exceptions::cstring_error(vm));
58+
}
5559
match User::from_name(name.as_str()).map_err(|err| err.into_pyexception(vm))? {
5660
Some(user) => Ok(Passwd::from(user)),
5761
None => {

0 commit comments

Comments
 (0)