diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index 929d8345..3fe6d220 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -58,6 +58,29 @@ ostree_validate_checksum_string (const char *sha256, return TRUE; } +gboolean +ostree_validate_rev (const char *rev, + GError **error) +{ + gboolean ret = FALSE; + GPtrArray *components = NULL; + + if (!ot_util_path_split_validate (rev, &components, error)) + goto out; + + if (components->len == 0) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Invalid empty rev"); + goto out; + } + + ret = TRUE; + out: + g_ptr_array_unref (components); + return ret; +} + GVariant * ostree_wrap_metadata_variant (OstreeObjectType type, GVariant *metadata) diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index 0772ca90..24489ce3 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -100,6 +100,8 @@ typedef enum { gboolean ostree_validate_checksum_string (const char *sha256, GError **error); +gboolean ostree_validate_rev (const char *rev, GError **error); + void ostree_checksum_update_stat (GChecksum *checksum, guint32 uid, guint32 gid, guint32 mode); const char * ostree_object_type_to_string (OstreeObjectType objtype); diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 0192b7a1..dc0baef7 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -339,20 +339,11 @@ ostree_repo_resolve_rev (OstreeRepo *self, g_return_val_if_fail (rev != NULL, FALSE); - /* This checks for .. and such, but we don't actually walk - * the parsed bits below. - */ - if (!ot_util_path_split_validate (rev, &components, error)) + if (!ostree_validate_rev (rev, error)) goto out; - if (components->len == 0) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Invalid empty rev"); - goto out; - } /* We intentionally don't allow a ref that looks like a checksum */ - else if (ostree_validate_checksum_string (rev, NULL)) + if (ostree_validate_checksum_string (rev, NULL)) { ret_rev = g_strdup (rev); }