lib/pull: Check whether summary is in normal form when loading it
authorPhilip Withnall <withnall@endlessm.com>
Mon, 19 Jun 2017 14:58:08 +0000 (15:58 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 27 Jun 2017 19:19:32 +0000 (19:19 +0000)
Check that it’s in normal form and has the correct type when loading it,
since it could come from an untrusted source.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #961
Approved by: cgwalters

src/libostree/ostree-repo-pull.c

index cc8a51eb6a3927282726606f428a17d7b6ed657b..0b7dae17b3f85356fcb786e1876f87ad2490356b 100644 (file)
@@ -3362,6 +3362,20 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
         pull_data->summary_data = g_bytes_ref (bytes_summary);
         pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes_summary, FALSE);
 
+        if (!g_variant_is_normal_form (pull_data->summary))
+          {
+            g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                                 "Not normal form");
+            goto out;
+          }
+        if (!g_variant_is_of_type (pull_data->summary, OSTREE_SUMMARY_GVARIANT_FORMAT))
+          {
+            g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                         "Doesn't match variant type '%s'",
+                         (char *)OSTREE_SUMMARY_GVARIANT_FORMAT);
+            goto out;
+          }
+
         if (bytes_sig)
           pull_data->summary_data_sig = g_bytes_ref (bytes_sig);
       }