pull: Cleanly error out on unknown schemes
Previous to this we'd trip an assertion `abort()` deep in the curl code if e.g. a user did `ostree remote add foo htttp://...` etc. Motivated by considering supporting "external remotes" where code outside ostree does a pull, but we want to reuse the signing verification infrastructure.
This commit is contained in:
1 parent
0fcf4a3f30
commit
0f3bccf640
4 files changed
+34
-2
No files matched your search
@@ -117,3 +117,21 @@ _ostree_fetcher_uri_to_string (OstreeFetcherURI *uri)
|
||||
{
|
||||
return soup_uri_to_string ((SoupURI*)uri, FALSE);
|
||||
}
|
||||
|
||||
|
||||
/* Only accept http, https, and file; particularly curl has a ton of other
|
||||
* backends like sftp that we don't want, and this also gracefully filters
|
||||
* out invalid input.
|
||||
*/
|
||||
gboolean
|
||||
_ostree_fetcher_uri_validate (OstreeFetcherURI *uri, GError **error)
|
||||
{
|
||||
const char *scheme = soup_uri_get_scheme ((SoupURI*)uri);
|
||||
// TODO only allow file if explicitly requested by a higher level
|
||||
if (!(g_str_equal (scheme, "http") || g_str_equal (scheme, "https") || g_str_equal (scheme, "file")))
|
||||
{
|
||||
g_autofree char *s = _ostree_fetcher_uri_to_string (uri);
|
||||
return glnx_throw (error, "Invalid URI scheme in %s", s);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -90,6 +90,9 @@ _ostree_fetcher_uri_get_path (OstreeFetcherURI *uri);
|
||||
char *
|
||||
_ostree_fetcher_uri_to_string (OstreeFetcherURI *uri);
|
||||
|
||||
gboolean
|
||||
_ostree_fetcher_uri_validate (OstreeFetcherURI *uri, GError **error);
|
||||
|
||||
GType _ostree_fetcher_get_type (void) G_GNUC_CONST;
|
||||
|
||||
OstreeFetcher *_ostree_fetcher_new (int tmpdir_dfd,
|
||||
|
||||
@@ -3446,6 +3446,9 @@ compute_effective_mirrorlist (OstreeRepo *self,
|
||||
if (!baseuri)
|
||||
return FALSE;
|
||||
|
||||
if (!_ostree_fetcher_uri_validate (baseuri, error))
|
||||
return FALSE;
|
||||
|
||||
*out_mirrorlist =
|
||||
g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free);
|
||||
g_ptr_array_add (*out_mirrorlist, g_steal_pointer (&baseuri));
|
||||
|
||||
Reference in new issue
Block a user