repo: Validate checksums have correct length

ostree_checksum_bytes_peek() can return NULL if the checksum has an
incorrect length (most likely from disk corruption) but most callers
are not prepared to handle this and would likely crash.

Use ostree_checksum_bytes_peek_validate() instead, which sets a
GError on an invalid checksum.
This commit is contained in:
Matthew Barnes committed 2015-11-17 20:35:54 -05:00
1 parent 45cee1bd70
commit 5307af5a7a
3 files changed
+59 -17

No files matched your search

+7 -2
View File
@@ -633,10 +633,15 @@ ostree_repo_remote_list_refs (OstreeRepo *self,
if (ref_name != NULL)
{
const guchar *csum_bytes;
g_variant_get_child (child, 1, "(t@aya{sv})", NULL, &csum_v, NULL);
csum_bytes = ostree_checksum_bytes_peek_validate (csum_v, error);
if (csum_bytes == NULL)
goto out;
ostree_checksum_inplace_from_bytes (csum_bytes, tmp_checksum);
ostree_checksum_inplace_from_bytes (ostree_checksum_bytes_peek (csum_v),
tmp_checksum);
g_hash_table_insert (ret_all_refs,
g_strdup (ref_name),
g_strdup (tmp_checksum));