-
Notifications
You must be signed in to change notification settings - Fork 54
xargs doesn't limit command line lengths properly #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “ 8000 Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, @tavianator . What you think about use something like: #[cfg(unix)]
fn count_osstr_chars_for_exec(s: &OsStr) -> (usize, usize) {
use std::os::unix::ffi::OsStrExt;
let cmd = Command::new(s);
let args: Vec<&OsStr> = cmd.get_args().collect();
// Include +1 for the null terminator.
(s.as_bytes().len() + 1, args.len())
} To this issue? We mantain the count for string and get argv count together. |
@Every2 I would strongly recommend using https://crates.io/crates/argmax, it already contains a well-tested implementation of command line length limiting. It was also recently added to this project's |
@tavianator I see. Just confirming if I understood correctly. The structure of the code shouldn't be changed, only the function |
No, i feel like the code in xargs/mod.rs should be mostly re-written to take advantage of the argmax crate instead of using its own logic (MaxArgsCommandSizeLimiter etc.) |
I'll start working on it then! One more thing. Is it better to send small PRs or send it all at once? |
From a quick look, there's at least an issue here:
findutils/src/xargs/mod.rs
Lines 141 to 146 in 36e3229
This needs to count not only the length of the string, but also the size of the pointer that ends up in
argv
/envp
.It might be worth using the https://crates.io/crates/argmax crate to do this accounting for us. It could also help for #6.
The text was updated successfully, but these errors were encountered: