From 897792ef3fb52265e995fc6454104bbb5c49baa8 Mon Sep 17 00:00:00 2001 From: Rob Gill Date: Fri, 8 Feb 2019 13:19:56 +1000 Subject: [PATCH] pkgman: Perform URL format validation Bug #13786 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Tests for validity of supplied URL before attempting to add it BUrl's isValid() is used to test the URL Change-Id: I49bfc266177f16052a46ca3dbc1fd6e8dd1ab6ae Reviewed-on: https://review.haiku-os.org/c/1020 Reviewed-by: Jérôme Duval --- src/bin/pkgman/command_add_repo.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/pkgman/command_add_repo.cpp b/src/bin/pkgman/command_add_repo.cpp index 6605f3900b..f8c15e2b45 100644 --- a/src/bin/pkgman/command_add_repo.cpp +++ b/src/bin/pkgman/command_add_repo.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -87,6 +88,13 @@ AddRepoCommand::Execute(int argc, const char* const* argv) status_t result; for (int i = 0; i < urlCount; ++i) { + // Test if a valid URL has been supplied before attempting to add + BUrl repoURL(repoURLs[i]); + if (!repoURL.IsValid()) { + result = B_BAD_VALUE; + DIE(result, "request for adding repository \"%s\" failed", + repoURLs[i]); + } AddRepositoryRequest addRequest(context, repoURLs[i], asUserRepository); result = addRequest.Process(true); if (result != B_OK) { @@ -102,7 +110,7 @@ AddRepoCommand::Execute(int argc, const char* const* argv) BPackageRoster roster; BRepositoryConfig repoConfig; roster.GetRepositoryConfig(repoName, &repoConfig); - + BRefreshRepositoryRequest refreshRequest(context, repoConfig); result = refreshRequest.Process(true); if (result != B_OK) {