# HG changeset patch # User J. Ali Harlow # Date 1527869941 -3600 # Node ID bd272d15bea44a1509b609475683e35298379666 # Parent 4084b55bfbd882ec21e8d0ea525cabb25f8857c2 Treat invalid URIs as programming errors diff -r 4084b55bfbd8 -r bd272d15bea4 plover/comps.c --- a/plover/comps.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/comps.c Fri Jun 01 17:19:01 2018 +0100 @@ -390,6 +390,7 @@ void *contents; size_t length; struct comps *comps; + g_return_val_if_fail(plover__uri_validate(uri),NULL); plover__uri_handler_init(); contents=razor_uri_get_contents(uri,&length,FALSE,&tmp_error); if (!contents) diff -r 4084b55bfbd8 -r bd272d15bea4 plover/import-yum.c --- a/plover/import-yum.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/import-yum.c Fri Jun 01 17:19:01 2018 +0100 @@ -347,6 +347,7 @@ struct razor_package *pkg; PloverPackageSet *set; PloverRepository *repository; + g_return_val_if_fail(plover__uri_validate(base_uri),NULL); plover__uri_handler_init(); ctx.importer=razor_importer_create(); ctx.state=YUM_STATE_BEGIN; @@ -461,6 +462,7 @@ PloverRepository *repository; PloverPackageSet *set; struct razor_set *razor; + g_return_val_if_fail(plover__uri_validate(base_uri),NULL); repository=plover_repository_new_from_yum_uri(base_uri,error); if (!repository) return NULL; diff -r 4084b55bfbd8 -r bd272d15bea4 plover/inputstream.c --- a/plover/inputstream.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/inputstream.c Fri Jun 01 17:19:01 2018 +0100 @@ -139,7 +139,7 @@ struct razor_error *tmp_error=NULL; GInputStream *stream; PloverRazorInputStreamPrivate *priv; - g_return_if_fail(uri!=NULL); + g_return_val_if_fail(plover__uri_validate(uri),NULL); buf=razor_uri_get_contents(uri,&len,FALSE,&tmp_error); if (!buf) { diff -r 4084b55bfbd8 -r bd272d15bea4 plover/packageset.c --- a/plover/packageset.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/packageset.c Fri Jun 01 17:19:01 2018 +0100 @@ -128,6 +128,7 @@ PloverPackageSetPrivate *priv; struct razor_error *error=NULL; g_return_val_if_fail(PLOVER_IS_PACKAGE_SET(set),FALSE); + g_return_val_if_fail(plover__uri_validate(root_uri),FALSE); if (exclusive) { root=razor_root_open(root_uri,NULL); diff -r 4084b55bfbd8 -r bd272d15bea4 plover/plover.h --- a/plover/plover.h Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/plover.h Fri Jun 01 17:19:01 2018 +0100 @@ -120,6 +120,8 @@ char *plover_vector_format_for_display(struct plover_vector *vector); void plover_vector_free(struct plover_vector *vector); +gboolean plover__uri_validate(const char *uri); + G_END_DECLS #endif /* __PLOVER_H__ */ diff -r 4084b55bfbd8 -r bd272d15bea4 plover/razor.c --- a/plover/razor.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/razor.c Fri Jun 01 17:19:01 2018 +0100 @@ -67,6 +67,7 @@ int r,count; GError *tmp_error=NULL; PloverPackage *package; + g_return_val_if_fail(plover__uri_validate(root_uri),-1); plover__uri_handler_init(); if (!*root_uri) root_uri="file:/"; @@ -176,6 +177,7 @@ { gboolean retval; PloverTransaction *transaction; + g_return_val_if_fail(plover__uri_validate(base_uri),FALSE); transaction=plover_transaction_new_install_uri(base_uri,prefix,pkgs,error); if (!transaction) return FALSE; @@ -203,6 +205,7 @@ { gboolean retval; PloverTransaction *transaction; + g_return_val_if_fail(plover__uri_validate(base_uri),FALSE); transaction=plover_transaction_new_update_uri(base_uri,prefix,pkgs,error); if (!transaction) return FALSE; @@ -418,6 +421,7 @@ static struct razor_set *(*next)(const char *uri,enum razor_set_flags flags, struct razor_error **error); struct razor_set *set; + g_return_val_if_fail(plover__uri_validate(uri),NULL); if (!next) next=dlsym(RTLD_NEXT,"razor_set_open"); set=(*next)(uri,flags,error); @@ -486,6 +490,7 @@ static struct razor_set *(*next)(const char *root_uri, struct razor_error **error); struct razor_set *set; + g_return_val_if_fail(plover__uri_validate(root_uri),NULL); if (!next) next=dlsym(RTLD_NEXT,"razor_root_open_read_only"); set=(*next)(root_uri,error); diff -r 4084b55bfbd8 -r bd272d15bea4 plover/transaction.c --- a/plover/transaction.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/transaction.c Fri Jun 01 17:19:01 2018 +0100 @@ -487,6 +487,7 @@ PloverRepository *upstream; g_return_val_if_fail(PLOVER_IS_TRANSACTION(transaction),FALSE); g_return_val_if_fail(transaction->upstream == NULL,FALSE); + g_return_val_if_fail(plover__uri_validate(base_uri),FALSE); upstream=plover_repository_new_from_yum_uri(base_uri,error); if (!upstream) return FALSE; @@ -584,6 +585,7 @@ const char *prefix,char **pkgs,GError **error) { PloverTransaction *transaction; + g_return_val_if_fail(plover__uri_validate(base_uri),NULL); transaction=plover_transaction_new(); plover_transaction_set_prefix(transaction,prefix); if (!plover_transaction_set_upstream_from_yum_uri(transaction,base_uri,error)) @@ -617,6 +619,7 @@ const char *prefix,char **pkgs,GError **error) { PloverTransaction *transaction; + g_return_val_if_fail(plover__uri_validate(base_uri),NULL); transaction=plover_transaction_new(); plover_transaction_set_prefix(transaction,prefix); if (!plover_transaction_set_upstream_from_yum_uri(transaction,base_uri, diff -r 4084b55bfbd8 -r bd272d15bea4 plover/util.c --- a/plover/util.c Fri Jun 01 15:26:27 2018 +0100 +++ b/plover/util.c Fri Jun 01 17:19:01 2018 +0100 @@ -356,3 +356,11 @@ } g_error_free(src); } + +gboolean plover__uri_validate(const char *uri) +{ + char *s; + s=razor_path_relative_to_uri(uri,".",NULL); + free(s); + return !!s; +}