ref: refs/heads/master commit 0c186e0d6dfd772f62e786fa91d8670aa4a0d490 Author: Ján Kupec <jkupec@suse.cz> Date: Fri Dec 4 14:43:43 2009 +0100 Don't allow an alias to start with '.' (bnc #473834) --- zypp/RepoManager.cc | 10 ++++++++++ zypp/repo/RepoException.cc | 2 ++ zypp/repo/RepoException.h | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 0 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 7f0cc0e..0616261 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -285,12 +285,22 @@ namespace zypp { if ( info.alias().empty() ) ZYPP_THROW( RepoNoAliasException() ); + // bnc #473834. Maybe we can match the alias against a regex to define + // and check for valid aliases + if ( info.alias()[0] == '.') + ZYPP_THROW(RepoInvalidAliasException( + info, _("Repository alias cannot start with dot."))); } inline void assert_alias( const ServiceInfo & info ) { if ( info.alias().empty() ) ZYPP_THROW( ServiceNoAliasException() ); + // bnc #473834. Maybe we can match the alias against a regex to define + // and check for valid aliases + if ( info.alias()[0] == '.') + ZYPP_THROW(ServiceInvalidAliasException( + info, _("Service alias cannot start with dot."))); } //////////////////////////////////////////////////////////////////////////// diff --git a/zypp/repo/RepoException.cc b/zypp/repo/RepoException.cc index 586e5ef..5543c43 100644 --- a/zypp/repo/RepoException.cc +++ b/zypp/repo/RepoException.cc @@ -64,6 +64,7 @@ namespace zypp DEF_CTORS( RepoNotCachedException, "Repository is not cached" ); DEF_CTORS( RepoNoUrlException, "Repository has no or invalid url defined." ); DEF_CTORS( RepoNoAliasException, "Repository has no alias defined." ); + DEF_CTORS( RepoInvalidAliasException, "Repository has an invalid alias." ); DEF_CTORS( RepoNotFoundException, "Repository not found." ); DEF_CTORS( RepoAlreadyExistsException, "Repository already exists." ); DEF_CTORS( RepoUnknownTypeException, "Repository type can't be determined." ); @@ -111,6 +112,7 @@ namespace zypp CLASS::CLASS( const ServiceInfo & service_r, const std::string & msg_r ) : ServiceException( service_r, msg_r ) {} DEF_CTORS( ServiceNoAliasException, "Service has no alias defined." ); + DEF_CTORS( ServiceInvalidAliasException, "Service has an invalid alias." ); DEF_CTORS( ServiceAlreadyExistsException, "Service already exists." ); DEF_CTORS( ServiceNoUrlException, "Service has no or invalid url defined." ); diff --git a/zypp/repo/RepoException.h b/zypp/repo/RepoException.h index d910ebd..50b75d3 100644 --- a/zypp/repo/RepoException.h +++ b/zypp/repo/RepoException.h @@ -98,6 +98,18 @@ namespace zypp }; /** + * Thrown when the repo alias is found to be invalid. + */ + class RepoInvalidAliasException : public RepoException + { + public: + RepoInvalidAliasException(); + RepoInvalidAliasException( const std::string & msg_r ); + RepoInvalidAliasException( const RepoInfo & info ); + RepoInvalidAliasException( const RepoInfo & info, const std::string & msg_r ); + }; + + /** * thrown when it was impossible to * match a repository */ @@ -194,6 +206,18 @@ namespace zypp ServiceNoAliasException( const ServiceInfo & service_r, const std::string & msg_r ); }; + /** + * Thrown when the repo alias is found to be invalid. + */ + class ServiceInvalidAliasException : public ServiceException + { + public: + ServiceInvalidAliasException(); + ServiceInvalidAliasException( const std::string & msg_r ); + ServiceInvalidAliasException( const ServiceInfo & info ); + ServiceInvalidAliasException( const ServiceInfo & info, const std::string & msg_r ); + }; + /** Service already exists and some unique attribute can't be duplicated. */ class ServiceAlreadyExistsException : public ServiceException -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org