Skip to content

Commit

Permalink
Fix crash when metaurl contains unsupported URI or text
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Dec 6, 2013
1 parent 3096601 commit 705dadb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Metalink2RequestGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Metalink2RequestGroup::createRequestGroup
createRequestGroupForUri(result, optionTemplate, uris,
/* ignoreForceSequential = */true,
/* ignoreLocalPath = */true);
if(!uris.empty()) {
if(!result.empty()) {
torrentRg = result[0];
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ EXTRA_DIST = 4096chunk.txt\
metalink4-groupbymetaurl.xml\
serialize_session.meta4\
metalink4-dosdirtraversal.xml\
base_uri.xml
base_uri.xml\
local-metaurl.meta4

clean-local:
-rm -rf ${a2_test_outdir}
16 changes: 16 additions & 0 deletions test/Metalink2RequestGroupTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Metalink2RequestGroupTest:public CppUnit::TestFixture {

CPPUNIT_TEST_SUITE(Metalink2RequestGroupTest);
CPPUNIT_TEST(testGenerate);
CPPUNIT_TEST(testGenerate_with_local_metaurl);
CPPUNIT_TEST(testGenerate_groupByMetaurl);
CPPUNIT_TEST(testGenerate_dosDirTraversal);
CPPUNIT_TEST_SUITE_END();
Expand All @@ -31,6 +32,7 @@ class Metalink2RequestGroupTest:public CppUnit::TestFixture {
}

void testGenerate();
void testGenerate_with_local_metaurl();
void testGenerate_groupByMetaurl();
void testGenerate_dosDirTraversal();
};
Expand Down Expand Up @@ -125,6 +127,20 @@ void Metalink2RequestGroupTest::testGenerate()
}
}

void Metalink2RequestGroupTest::testGenerate_with_local_metaurl()
{
std::vector<std::shared_ptr<RequestGroup> > groups;
option_->put(PREF_DIR, "/tmp");
// local metaurl does not work without --metalink-base-uri option.
// Make sure that it does not crash with local metaurl.
Metalink2RequestGroup().generate(groups, A2_TEST_DIR"/local-metaurl.meta4",
option_);
CPPUNIT_ASSERT_EQUAL((size_t)1, groups.size());
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/README"),
groups[0]->getDownloadContext()->getFirstFileEntry()
->getRemainingUris()[0]);
}

void Metalink2RequestGroupTest::testGenerate_groupByMetaurl()
{
std::vector<std::shared_ptr<RequestGroup> > groups;
Expand Down
8 changes: 8 additions & 0 deletions test/local-metaurl.meta4
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
<file name="t/README">
<!-- require absolute URI here -->
<metaurl mediatype="torrent">README.torrent</metaurl>
<url type="http">http://example.org/README</url>
</file>
</metalink>

0 comments on commit 705dadb

Please sign in to comment.