From edb1cf29aca139eece566920f906cc3133968c6b Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 7 Aug 2024 20:37:56 +0200 Subject: [PATCH] [platform] launcher: skipping and flagging corrupted .vmoptions file (IJPL-159819) GitOrigin-RevId: 27b7eaa2636c02a70a4e818df993b451e89e8c2f --- native/XPlatLauncher/src/default.rs | 15 +++++++++------ native/XPlatLauncher/tests/default_tests.rs | 8 ++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/native/XPlatLauncher/src/default.rs b/native/XPlatLauncher/src/default.rs index 92f009944003..808b2d263a32 100644 --- a/native/XPlatLauncher/src/default.rs +++ b/native/XPlatLauncher/src/default.rs @@ -236,17 +236,17 @@ impl DefaultLaunchConfiguration { /// the corresponding distribution option must be omitted. fn collect_vm_options_from_files(&self, vm_options: &mut Vec) -> Result<()> { debug!("[1] Reading main VM options file: {:?}", self.vm_options_path); - let dist_vm_options = read_vm_options(&self.vm_options_path)?; + let (dist_vm_options, _) = read_vm_options(&self.vm_options_path)?; debug!("[2] Looking for user VM options file"); - let (user_vm_options, vm_options_path) = match self.get_user_vm_options_file() { + let ((user_vm_options, corrupted), vm_options_path) = match self.get_user_vm_options_file() { Ok(path) => { debug!("Reading user VM options file: {:?}", path); (read_vm_options(&path)?, path) } Err(e) => { debug!("Failed: {}", e.to_string()); - (Vec::new(), self.vm_options_path.clone()) + ((Vec::new(), false), self.vm_options_path.clone()) } }; @@ -266,6 +266,9 @@ impl DefaultLaunchConfiguration { vm_options.extend(user_vm_options); vm_options.push(jvm_property!("jb.vmOptionsFile", vm_options_path.to_string_checked()?)); + if corrupted { + vm_options.push(jvm_property!("jb.vmOptionsFile.corrupted", "true")) + } Ok(()) } @@ -304,7 +307,7 @@ impl DefaultLaunchConfiguration { } } -fn read_vm_options(path: &Path) -> Result> { +fn read_vm_options(path: &Path) -> Result<(Vec, bool)> { let file = File::open(path)?; let mut vm_options = Vec::with_capacity(50); @@ -314,13 +317,13 @@ fn read_vm_options(path: &Path) -> Result> { continue; } if line.contains('\0') { - bail!("Invalid character ('\\0') found in VM options file: {:?}", path); + return Ok((Vec::new(), true)); } vm_options.push(line); } debug!("{} line(s)", vm_options.len()); - Ok(vm_options) + Ok((vm_options, false)) } pub fn read_product_info(product_info_path: &Path) -> Result { diff --git a/native/XPlatLauncher/tests/default_tests.rs b/native/XPlatLauncher/tests/default_tests.rs index a81a9393848a..0439ccba7cc6 100644 --- a/native/XPlatLauncher/tests/default_tests.rs +++ b/native/XPlatLauncher/tests/default_tests.rs @@ -247,13 +247,9 @@ mod tests { let mut test = prepare_test_env(LauncherLocation::Standard); test.create_toolbox_vm_options("\0\0\0\0-Xmx512m\n"); - let result = run_launcher_ext(&test, &LauncherRunSpec::standard()); + let dump = run_launcher_ext(&test, LauncherRunSpec::standard().with_dump().assert_status()).dump(); - assert!(!result.exit_status.success(), "expected to fail:{:?}", result); - - let nul_message = "Invalid character ('\\0') found in VM options file"; - let nul_message_present = result.stderr.find(nul_message); - assert!(nul_message_present.is_some(), "Error message ('{}') is missing: {:?}", nul_message, result); + assert_eq!(dump.systemProperties["jb.vmOptionsFile.corrupted"], "true"); } #[test]