Skip to content

Commit 90df48f

Browse files
committed
fix(updater): panic when updating with empty current_exe_args (#2335)
1 parent b3bf742 commit 90df48f

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

plugins/updater/src/updater.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,13 @@ impl Update {
631631
let updater_type = self.extract(bytes)?;
632632

633633
let install_mode = self.config.install_mode();
634-
let current_args = &self.current_exe_args()[1..];
634+
let current_exe_args = self.current_exe_args();
635+
let current_args =
636+
current_exe_args
637+
.split_first()
638+
.map(|(_, args_without_exe)| args_without_exe)
639+
.unwrap_or(&[]);
640+
635641
let msi_args;
636642

637643
let installer_args: Vec<&OsStr> = match &updater_type {
@@ -640,25 +646,35 @@ impl Update {
640646
.iter()
641647
.map(OsStr::new)
642648
.chain(once(OsStr::new("/UPDATE")))
643-
.chain(once(OsStr::new("/ARGS")))
644-
.chain(current_args.to_vec())
649+
.chain(
650+
if current_args.len() > 0 {
651+
Some(once(OsStr::new("/ARGS")).chain(current_args.iter().map(|arg| *arg)))
652+
} else {
653+
None
654+
}.into_iter().flatten()
655+
)
645656
.chain(self.installer_args())
646657
.collect(),
647658
WindowsUpdaterType::Msi { path, .. } => {
648-
let escaped_args = current_args
649-
.iter()
650-
.map(escape_msi_property_arg)
651-
.collect::<Vec<_>>()
652-
.join(" ");
653-
msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""));
659+
if current_args.len() > 0 {
660+
let escaped_args = current_args
661+
.iter()
662+
.map(escape_msi_property_arg)
663+
.collect::<Vec<_>>()
664+
.join(" ");
665+
msi_args = Some(OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\"")));
666+
}
667+
else {
668+
msi_args = None;
669+
}
654670

655671
[OsStr::new("/i"), path.as_os_str()]
656672
.into_iter()
657673
.chain(install_mode.msiexec_args().iter().map(OsStr::new))
658674
.chain(once(OsStr::new("/promptrestart")))
659675
.chain(self.installer_args())
660676
.chain(once(OsStr::new("AUTOLAUNCHAPP=True")))
661-
.chain(once(msi_args.as_os_str()))
677+
.chain(msi_args.iter().map(|args| args.as_os_str()))
662678
.collect()
663679
}
664680
};

0 commit comments

Comments
 (0)