summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-09-28 10:15:13 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-10-01 15:07:05 +0100
commit1b2a2d596c01806fdafe689368bc065865bd5d57 (patch)
treeef23845732a3ade05af195a6bfd38f6b777acbd1 /src
parentc618a5137308b5aef0047fce252374cf4a168ac3 (diff)
downloadlibguestfs-1b2a2d596c01806fdafe689368bc065865bd5d57.tar.gz
libguestfs-1b2a2d596c01806fdafe689368bc065865bd5d57.tar.xz
libguestfs-1b2a2d596c01806fdafe689368bc065865bd5d57.zip
inspection: Fix calls to case_sensitive_path (RHBZ#858126).
Don't assume that if guestfs_case_sensitive_path returns NULL, that it means the file does not exist. The (previously undefined) behaviour of case_sensitive_path was that a NULL return meant "either the file doesn't exist or some other error". However in commit 973581780d8a006f336684fef6762801402d775d this was changed so that if the last element of the path didn't exist, it was assumed to be a new file and the (non-NULL) path of the new file is returned. This change breaks code (including in libguestfs) which tries to use case_sensitive_path as a dual-purpose call to fix-up a path for Windows and test if the file exists. Such code should be rewritten so that it explicitly tests for file existence after calling case_sensitive_path. I examined all the calls to case_sensitive_path in libguestfs and modified them where necessary. Cherry picked from commit 9ea6e9701461e594033999150f930cc4fafec4d2. (cherry picked from commit ff610469fb8ad1d27dac5d3cb2f1e007d8c0ecc7)
Diffstat (limited to 'src')
-rw-r--r--src/inspect_apps.c7
-rw-r--r--src/inspect_fs_windows.c41
2 files changed, 29 insertions, 19 deletions
diff --git a/src/inspect_apps.c b/src/inspect_apps.c
index 2ad2aadc..9a610d69 100644
--- a/src/inspect_apps.c
+++ b/src/inspect_apps.c
@@ -423,12 +423,9 @@ list_applications_windows (guestfs_h *g, struct inspect_fs *fs)
snprintf (software, len, "%s/system32/config/software",
fs->windows_systemroot);
- char *software_path = guestfs___case_sensitive_path_silently (g, software);
- if (!software_path) {
- /* Missing software hive is a problem. */
- error (g, "no HKLM\\SOFTWARE hive found in the guest");
+ char *software_path = guestfs_case_sensitive_path (g, software);
+ if (!software_path)
return NULL;
- }
char *software_hive = NULL;
struct guestfs_application_list *ret = NULL;
diff --git a/src/inspect_fs_windows.c b/src/inspect_fs_windows.c
index d04024bc..a842e49d 100644
--- a/src/inspect_fs_windows.c
+++ b/src/inspect_fs_windows.c
@@ -162,11 +162,9 @@ guestfs___check_windows_root (guestfs_h *g, struct inspect_fs *fs)
return -1;
}
- systemroot = guestfs___case_sensitive_path_silently (g, systemroots[i]);
- if (!systemroot) {
- error (g, _("cannot resolve Windows %%SYSTEMROOT%%"));
+ systemroot = guestfs_case_sensitive_path (g, systemroots[i]);
+ if (!systemroot)
return -1;
- }
debug (g, "windows %%SYSTEMROOT%% = %s", systemroot);
@@ -194,9 +192,10 @@ check_windows_arch (guestfs_h *g, struct inspect_fs *fs)
char cmd_exe[len];
snprintf (cmd_exe, len, "%s/system32/cmd.exe", fs->windows_systemroot);
- char *cmd_exe_path = guestfs___case_sensitive_path_silently (g, cmd_exe);
+ /* Should exist because of previous check above in has_windows_systemroot. */
+ char *cmd_exe_path = guestfs_case_sensitive_path (g, cmd_exe);
if (!cmd_exe_path)
- return 0;
+ return -1;
char *arch = guestfs_file_architecture (g, cmd_exe_path);
free (cmd_exe_path);
@@ -214,16 +213,23 @@ check_windows_arch (guestfs_h *g, struct inspect_fs *fs)
static int
check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
{
+ int r;
size_t len = strlen (fs->windows_systemroot) + 64;
char software[len];
snprintf (software, len, "%s/system32/config/software",
fs->windows_systemroot);
- char *software_path = guestfs___case_sensitive_path_silently (g, software);
+ char *software_path = guestfs_case_sensitive_path (g, software);
if (!software_path)
- /* If the software hive doesn't exist, just accept that we cannot
- * find product_name etc.
- */
+ return -1;
+
+ r = guestfs_is_file (g, software_path);
+ if (r == -1)
+ return -1;
+ /* If the software hive doesn't exist, just accept that we cannot
+ * find product_name etc.
+ */
+ if (r == 0)
return 0;
char *software_hive = NULL;
@@ -328,16 +334,23 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs)
static int
check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs)
{
+ int r;
size_t len = strlen (fs->windows_systemroot) + 64;
char system[len];
snprintf (system, len, "%s/system32/config/system",
fs->windows_systemroot);
- char *system_path = guestfs___case_sensitive_path_silently (g, system);
+ char *system_path = guestfs_case_sensitive_path (g, system);
if (!system_path)
- /* If the system hive doesn't exist, just accept that we cannot
- * find hostname etc.
- */
+ return -1;
+
+ r = guestfs_is_file (g, system_path);
+ if (r == -1)
+ return -1;
+ /* If the system hive doesn't exist, just accept that we cannot
+ * find hostname etc.
+ */
+ if (r == 0)
return 0;
char *system_hive = NULL;