|
| 1 | +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use std::fs; |
| 12 | +use std::io; |
| 13 | + |
| 14 | +fn assert_invalid_input<T>(on: &str, result: io::Result<T>) { |
| 15 | + fn inner(on: &str, result: io::Result<()>) { |
| 16 | + match result { |
| 17 | + Ok(()) => panic!("{} didn't return an error on a path with NUL", on), |
| 18 | + Err(e) => assert!(e.kind() == io::ErrorKind::InvalidInput, |
| 19 | + "{} returned a strange {:?} on a path with NUL", on, e.kind()), |
| 20 | + } |
| 21 | + } |
| 22 | + inner(on, result.map(|_| ())) |
| 23 | +} |
| 24 | + |
| 25 | +fn main() { |
| 26 | + assert_invalid_input("File::open", fs::File::open("\0")); |
| 27 | + assert_invalid_input("File::create", fs::File::create("\0")); |
| 28 | + assert_invalid_input("remove_file", fs::remove_file("\0")); |
| 29 | + assert_invalid_input("metadata", fs::metadata("\0")); |
| 30 | + assert_invalid_input("symlink_metadata", fs::symlink_metadata("\0")); |
| 31 | + assert_invalid_input("rename1", fs::rename("\0", "a")); |
| 32 | + assert_invalid_input("rename2", fs::rename("a", "\0")); |
| 33 | + assert_invalid_input("copy1", fs::copy("\0", "a")); |
| 34 | + assert_invalid_input("copy2", fs::copy("a", "\0")); |
| 35 | + assert_invalid_input("hard_link1", fs::hard_link("\0", "a")); |
| 36 | + assert_invalid_input("hard_link2", fs::hard_link("a", "\0")); |
| 37 | + assert_invalid_input("soft_link1", fs::soft_link("\0", "a")); |
| 38 | + assert_invalid_input("soft_link2", fs::soft_link("a", "\0")); |
| 39 | + assert_invalid_input("read_link", fs::read_link("\0")); |
| 40 | + assert_invalid_input("canonicalize", fs::canonicalize("\0")); |
| 41 | + assert_invalid_input("create_dir", fs::create_dir("\0")); |
| 42 | + assert_invalid_input("create_dir_all", fs::create_dir_all("\0")); |
| 43 | + assert_invalid_input("remove_dir", fs::remove_dir("\0")); |
| 44 | + assert_invalid_input("remove_dir_all", fs::remove_dir_all("\0")); |
| 45 | + assert_invalid_input("read_dir", fs::read_dir("\0")); |
| 46 | + assert_invalid_input("set_permissions", |
| 47 | + fs::set_permissions("\0", fs::metadata(".").unwrap().permissions())); |
| 48 | +} |
0 commit comments