From 90df48fd1252b9933360a41748e187bad0e24e43 Mon Sep 17 00:00:00 2001 From: Tal Zion Date: Sun, 19 Jan 2025 19:47:34 +0200 Subject: [PATCH 1/2] fix(updater): panic when updating with empty current_exe_args (#2335) --- plugins/updater/src/updater.rs | 36 ++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index f9209a00..37ea4d71 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -631,7 +631,13 @@ impl Update { let updater_type = self.extract(bytes)?; let install_mode = self.config.install_mode(); - let current_args = &self.current_exe_args()[1..]; + let current_exe_args = self.current_exe_args(); + let current_args = + current_exe_args + .split_first() + .map(|(_, args_without_exe)| args_without_exe) + .unwrap_or(&[]); + let msi_args; let installer_args: Vec<&OsStr> = match &updater_type { @@ -640,17 +646,27 @@ impl Update { .iter() .map(OsStr::new) .chain(once(OsStr::new("/UPDATE"))) - .chain(once(OsStr::new("/ARGS"))) - .chain(current_args.to_vec()) + .chain( + if current_args.len() > 0 { + Some(once(OsStr::new("/ARGS")).chain(current_args.iter().map(|arg| *arg))) + } else { + None + }.into_iter().flatten() + ) .chain(self.installer_args()) .collect(), WindowsUpdaterType::Msi { path, .. } => { - let escaped_args = current_args - .iter() - .map(escape_msi_property_arg) - .collect::>() - .join(" "); - msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\"")); + if current_args.len() > 0 { + let escaped_args = current_args + .iter() + .map(escape_msi_property_arg) + .collect::>() + .join(" "); + msi_args = Some(OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""))); + } + else { + msi_args = None; + } [OsStr::new("/i"), path.as_os_str()] .into_iter() @@ -658,7 +674,7 @@ impl Update { .chain(once(OsStr::new("/promptrestart"))) .chain(self.installer_args()) .chain(once(OsStr::new("AUTOLAUNCHAPP=True"))) - .chain(once(msi_args.as_os_str())) + .chain(msi_args.iter().map(|args| args.as_os_str())) .collect() } }; From e7b7a8d50ea038d3de093295028b95b1987e63eb Mon Sep 17 00:00:00 2001 From: Tal Zion Date: Mon, 17 Feb 2025 18:37:20 +0200 Subject: [PATCH 2/2] fix formatting --- plugins/updater/src/updater.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 37ea4d71..653712c4 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -632,12 +632,11 @@ impl Update { let install_mode = self.config.install_mode(); let current_exe_args = self.current_exe_args(); - let current_args = - current_exe_args - .split_first() - .map(|(_, args_without_exe)| args_without_exe) - .unwrap_or(&[]); - + let current_args = current_exe_args + .split_first() + .map(|(_, args_without_exe)| args_without_exe) + .unwrap_or(&[]); + let msi_args; let installer_args: Vec<&OsStr> = match &updater_type { @@ -651,7 +650,9 @@ impl Update { Some(once(OsStr::new("/ARGS")).chain(current_args.iter().map(|arg| *arg))) } else { None - }.into_iter().flatten() + } + .into_iter() + .flatten(), ) .chain(self.installer_args()) .collect(), @@ -663,8 +664,7 @@ impl Update { .collect::>() .join(" "); msi_args = Some(OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""))); - } - else { + } else { msi_args = None; }