From 8ee7da48c54e4baafa90dd787cd3708834205b52 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 17 Feb 2017 10:17:57 +0000 Subject: [PATCH] lib, tools, v2v: Use unsafe flag when reading (but NOT writing) hives. Pass the HIVEX_OPEN_UNSAFE flag when opening hives for reading. Do NOT pass it when opening hives for writing. This should make inspection, virt-win-reg and virt-v2v more tolerant about handling Windows Registry corruption, without increasing the risk of causing new corruption in hives. --- lib/inspect-apps.c | 4 +++- lib/inspect-fs-windows.c | 8 ++++++-- tools/virt-win-reg | 3 ++- v2v/windows.ml | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c index b377f57c7..0f2b505b8 100644 --- a/lib/inspect-apps.c +++ b/lib/inspect-apps.c @@ -792,7 +792,9 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs) return NULL; if (guestfs_hivex_open (g, software_path, - GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1) + GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, + GUESTFS_HIVEX_OPEN_UNSAFE, 1, + -1) == -1) return NULL; /* Allocate apps list. */ diff --git a/lib/inspect-fs-windows.c b/lib/inspect-fs-windows.c index c139051d0..fc0b42bb6 100644 --- a/lib/inspect-fs-windows.c +++ b/lib/inspect-fs-windows.c @@ -283,7 +283,9 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) bool ignore_currentversion = false; if (guestfs_hivex_open (g, software_path, - GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1) + GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, + GUESTFS_HIVEX_OPEN_UNSAFE, 1, + -1) == -1) return -1; node = guestfs_hivex_root (g); @@ -405,7 +407,9 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) { NULL /* current control set */, "Services", "Tcpip", "Parameters" }; if (guestfs_hivex_open (g, system_path, - GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, -1) == -1) + GUESTFS_HIVEX_OPEN_VERBOSE, g->verbose, + GUESTFS_HIVEX_OPEN_UNSAFE, 1, + -1) == -1) goto out; root = guestfs_hivex_root (g); diff --git a/tools/virt-win-reg b/tools/virt-win-reg index 18100e775..8ddc4f99c 100755 --- a/tools/virt-win-reg +++ b/tools/virt-win-reg @@ -335,7 +335,8 @@ if (!$merge) { # Export mode. download_hive ($hivefile, $hiveshortname); # Open it. - my $h = Win::Hivex->open ("$tmpdir/$hiveshortname", debug => $debug); + my $h = Win::Hivex->open ("$tmpdir/$hiveshortname", + unsafe => 1, debug => $debug); unless ($name) { # Export it. diff --git a/v2v/windows.ml b/v2v/windows.ml index 9e8ef1e9e..79a14aa71 100644 --- a/v2v/windows.ml +++ b/v2v/windows.ml @@ -49,7 +49,8 @@ and (=~) str rex = let with_hive_readonly (g : Guestfs.guestfs) hive_filename f = let verbose = verbose () in - g#hivex_open ~write:false ~verbose (* ~debug:verbose *) hive_filename; + g#hivex_open ~write:false ~unsafe:true ~verbose (* ~debug:verbose *) + hive_filename; protect ~f:( fun () -> let root = g#hivex_root () in