[Libguestfs] [PATCH 4/5] inspect: windows: Make is_systemroot check code more robust.

Richard W.M. Jones rjones at redhat.com
Sun Mar 6 23:09:00 UTC 2016


We rely on this function for security to ensure the caller cannot set
windows_systemroot to a very long or bogus value.
---
 src/inspect-fs-windows.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c
index 5adf145..0a60d7d 100644
--- a/src/inspect-fs-windows.c
+++ b/src/inspect-fs-windows.c
@@ -83,18 +83,18 @@ static char *extract_guid_from_registry_blob (guestfs_h *g, const void *blob);
 static int
 is_systemroot (guestfs_h *const g, const char *systemroot)
 {
-  char path[256];
+  CLEANUP_FREE char *path1 = NULL, *path2 = NULL, *path3 = NULL;
 
-  snprintf (path, sizeof path, "%s/system32", systemroot);
-  if (!guestfs_int_is_dir_nocase (g, path))
+  path1 = safe_asprintf (g, "%s/system32", systemroot);
+  if (!guestfs_int_is_dir_nocase (g, path1))
     return 0;
 
-  snprintf (path, sizeof path, "%s/system32/config", systemroot);
-  if (!guestfs_int_is_dir_nocase (g, path))
+  path2 = safe_asprintf (g, "%s/system32/config", systemroot);
+  if (!guestfs_int_is_dir_nocase (g, path2))
     return 0;
 
-  snprintf (path, sizeof path, "%s/system32/cmd.exe", systemroot);
-  if (!guestfs_int_is_file_nocase (g, path))
+  path3 = safe_asprintf (g, "%s/system32/cmd.exe", systemroot);
+  if (!guestfs_int_is_file_nocase (g, path3))
     return 0;
 
   return 1;
-- 
2.5.0




More information about the Libguestfs mailing list