Fix crash when calling a command with a name like rÿd

This commit is contained in:
Oren Watson 2023-01-21 09:40:35 +00:00
parent aa6976cd03
commit 5544689321

View file

@ -1,21 +1,21 @@
#![allow(non_snake_case)]
use std::{env, io, os::unix::process::CommandExt, process::Command};
use std::{env, io, os::unix::process::CommandExt, process::Command, ffi::OsString};
use syslog::{unix, Facility::LOG_AUTH, Formatter3164};
fn main() -> io::Result<()> {
if env::args().nth(0).unwrap() != "🥺" {
if env::args_os().nth(0).unwrap() != "🥺" {
eprintln!("error: called 🥺 with name {}", env::args().nth(0).unwrap());
return Ok(());
}
if env::args().len() == 1 {
if env::args_os().len() == 1 {
eprintln!("usage: {} <command> [args]", env::args().nth(0).unwrap());
return Ok(());
}
let program = env::args().nth(1).unwrap();
let args = env::args().skip(2).collect::<Vec<String>>();
let program = env::args_os().nth(1).unwrap();
let args = env::args_os().skip(2).collect::<Vec<OsString>>();
let mut writer = unix(Formatter3164 {
facility: LOG_AUTH,
hostname: None,