inspect: Refuse to download software hive if it is huge.
[libguestfs.git] / src / inspect.c
index 58a49a6..bd6d189 100644 (file)
@@ -349,7 +349,7 @@ parse_release_file (guestfs_h *g, struct inspect_fs *fs,
   if (product_name == NULL)
     return -1;
   if (product_name[0] == NULL) {
-    error (g, "%s: file is empty", release_filename);
+    error (g, _("%s: file is empty"), release_filename);
     guestfs___free_string_list (product_name);
     return -1;
   }
@@ -629,6 +629,14 @@ static int
 check_fstab (guestfs_h *g, struct inspect_fs *fs)
 {
   int r;
+  int64_t size;
+
+  /* Security: Refuse to do this if /etc/fstab is huge. */
+  size = guestfs_filesize (g, "/etc/fstab");
+  if (size == -1 || size > 100000) {
+    error (g, _("size of /etc/fstab unreasonable (%" PRIi64 " bytes)"), size);
+    return -1;
+  }
 
   /* XXX What if !feature_available (g, "augeas")? */
   if (guestfs_aug_init (g, "/", 16|32) == -1)
@@ -654,7 +662,7 @@ check_fstab_aug_open (guestfs_h *g, struct inspect_fs *fs)
     return -1;
 
   if (lines[0] == NULL) {
-    error (g, "could not parse /etc/fstab or empty file");
+    error (g, _("could not parse /etc/fstab or empty file"));
     guestfs___free_string_list (lines);
     return -1;
   }
@@ -942,6 +950,14 @@ check_windows_registry (guestfs_h *g, struct inspect_fs *fs)
   hive_h *h = NULL;
   hive_value_h *values = NULL;
 
+  /* Security: Refuse to download registry if it is huge. */
+  int64_t size = guestfs_filesize (g, software_path);
+  if (size == -1 || size > 100000000) {
+    error (g, _("size of %s unreasonable (%" PRIi64 " bytes)"),
+           software_path, size);
+    goto out;
+  }
+
   if (mkdtemp (dir) == NULL) {
     perrorf (g, "mkdtemp");
     goto out;
@@ -1079,7 +1095,7 @@ parse_unsigned_int (guestfs_h *g, const char *str)
   long ret;
   int r = xstrtol (str, NULL, 10, &ret, "");
   if (r != LONGINT_OK) {
-    error (g, "could not parse integer in version number: %s", str);
+    error (g, _("could not parse integer in version number: %s"), str);
     return -1;
   }
   return ret;