diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 73b8706db4..29acf48dfa 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -788,6 +788,12 @@ fn build_options( let column_width = parse_usize(matches, options::COLUMN_WIDTH).unwrap_or(Ok(default_column_width))?; + if column_width == 0 { + return Err(PrError::EncounteredErrors { + msg: "invalid --width argument '0'".to_string(), + }); + } + let page_width = if matches.get_flag(options::JOIN_LINES) { None } else { @@ -797,6 +803,12 @@ fn build_options( } }; + if page_width == Some(0) { + return Err(PrError::EncounteredErrors { + msg: "invalid --page-width argument '0'".to_string(), + }); + } + let re_col = Regex::new(r"\s*-(\d+)\s*").unwrap(); let res = re_col.captures(free_args).map(|i| { diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 16a4032a7f..b7d500e6af 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -930,3 +930,19 @@ fn test_zero_expand_tab_width() { .fails_with_code(1) .stderr_only(expected); } + +#[test] +fn test_zero_column_width() { + new_ucmd!() + .args(&["-w", "0"]) + .fails_with_code(1) + .stderr_is("pr: invalid --width argument '0'\n"); +} + +#[test] +fn test_zero_page_width() { + new_ucmd!() + .args(&["-W", "0"]) + .fails_with_code(1) + .stderr_is("pr: invalid --page-width argument '0'\n"); +}