mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
expand: avoid an infinite loop
This commit is contained in:
parent
8d24036f5c
commit
3d356d47b3
2 changed files with 17 additions and 2 deletions
|
@ -11,11 +11,12 @@ use std::fmt;
|
|||
use std::fs::File;
|
||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||
use std::num::IntErrorKind;
|
||||
use std::path::Path;
|
||||
use std::str::from_utf8;
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult};
|
||||
use uucore::{format_usage, help_about, help_usage};
|
||||
use uucore::error::{set_exit_code, FromIo, UError, UResult};
|
||||
use uucore::{format_usage, help_about, help_usage, show_error};
|
||||
|
||||
const ABOUT: &str = help_about!("expand.md");
|
||||
const USAGE: &str = help_usage!("expand.md");
|
||||
|
@ -465,6 +466,12 @@ fn expand(options: &Options) -> UResult<()> {
|
|||
let mut buf = Vec::new();
|
||||
|
||||
for file in &options.files {
|
||||
if Path::new(file).is_dir() {
|
||||
show_error!("{}: Is a directory", file);
|
||||
set_exit_code(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut fh = open(file)?;
|
||||
|
||||
while match fh.read_until(b'\n', &mut buf) {
|
||||
|
|
|
@ -409,3 +409,11 @@ int main() {
|
|||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expand_directory() {
|
||||
new_ucmd!()
|
||||
.args(&["."])
|
||||
.fails()
|
||||
.stderr_contains("expand: .: Is a directory");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue