Skip to content

Commit e9c6c53

Browse files
authored
Merge pull request #10196 from oech3/mknod-u32
mknod: Avoid major/minor No overflow
2 parents 0d403a4 + 28e9439 commit e9c6c53

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/uu/mknod/src/mknod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
143143

144144
let dev = match (
145145
file_type,
146-
matches.get_one::<u64>(options::MAJOR),
147-
matches.get_one::<u64>(options::MINOR),
146+
matches.get_one::<u32>(options::MAJOR),
147+
matches.get_one::<u32>(options::MINOR),
148148
) {
149149
(FileType::Fifo, None, None) => 0,
150150
(FileType::Fifo, _, _) => {
@@ -208,13 +208,13 @@ pub fn uu_app() -> Command {
208208
Arg::new(options::MAJOR)
209209
.value_name(options::MAJOR)
210210
.help(translate!("mknod-help-major"))
211-
.value_parser(value_parser!(u64)),
211+
.value_parser(value_parser!(u32)),
212212
)
213213
.arg(
214214
Arg::new(options::MINOR)
215215
.value_name(options::MINOR)
216216
.help(translate!("mknod-help-minor"))
217-
.value_parser(value_parser!(u64)),
217+
.value_parser(value_parser!(u32)),
218218
)
219219
.arg(
220220
Arg::new(options::SECURITY_CONTEXT)

tests/by-util/test_mknod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ use uutests::util::TestScenario;
1414
use uutests::util::run_ucmd_as_root;
1515
use uutests::util_name;
1616

17+
//Reject 2^32+1 major/minor device number
18+
#[test]
19+
fn test_mknod_overflow_major_minor() {
20+
new_ucmd!()
21+
.arg("lg32")
22+
.arg("c")
23+
.arg("4294967296")
24+
.arg("1")
25+
.fails_with_code(1)
26+
.no_stdout()
27+
.stderr_contains("invalid value '4294967296'"); //clap generated message, thats fine.
28+
}
29+
1730
#[test]
1831
fn test_mknod_invalid_arg() {
1932
new_ucmd!()

0 commit comments

Comments
 (0)