mirror of https://github.com/aria2/aria2
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Replaced '/' and '_' with '_' in HTTP/FTP filename. * src/A2STR.cc * src/A2STR.h * src/FtpNegotiationCommand.cc * src/HttpResponseCommand.cc * src/util.cc * src/util.h * test/UtilTest.ccpull/1/head
parent
4c89170488
commit
768f78f771
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Replaced '/' and '_' with '_' in HTTP/FTP filename.
|
||||||
|
* src/A2STR.cc
|
||||||
|
* src/A2STR.h
|
||||||
|
* src/FtpNegotiationCommand.cc
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
* src/util.cc
|
||||||
|
* src/util.h
|
||||||
|
* test/UtilTest.cc
|
||||||
|
|
||||||
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-01-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Treat --dir="" as --dir="."
|
Treat --dir="" as --dir="."
|
||||||
|
|
|
@ -56,4 +56,8 @@ const std::string A2STR::SEMICOLON_C(";");
|
||||||
|
|
||||||
const std::string A2STR::EQUAL_C("=");
|
const std::string A2STR::EQUAL_C("=");
|
||||||
|
|
||||||
|
const std::string A2STR::UNDERSCORE_C("_");
|
||||||
|
|
||||||
|
const std::string A2STR::BACK_SLASH_C("\\");
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -62,6 +62,10 @@ public:
|
||||||
static const std::string SEMICOLON_C;
|
static const std::string SEMICOLON_C;
|
||||||
|
|
||||||
static const std::string EQUAL_C;
|
static const std::string EQUAL_C;
|
||||||
|
|
||||||
|
static const std::string UNDERSCORE_C;
|
||||||
|
|
||||||
|
static const std::string BACK_SLASH_C;
|
||||||
};
|
};
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
|
|
|
@ -337,7 +337,8 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
||||||
if(_fileEntry->getPath().empty()) {
|
if(_fileEntry->getPath().empty()) {
|
||||||
_fileEntry->setPath
|
_fileEntry->setPath
|
||||||
(util::applyDir
|
(util::applyDir
|
||||||
(getDownloadContext()->getDir(), util::urldecode(req->getFile())));
|
(getDownloadContext()->getDir(),
|
||||||
|
util::fixTaintedBasename(util::urldecode(req->getFile()))));
|
||||||
}
|
}
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
||||||
|
|
|
@ -132,7 +132,8 @@ bool HttpResponseCommand::executeInternal()
|
||||||
if(_fileEntry->getPath().empty()) {
|
if(_fileEntry->getPath().empty()) {
|
||||||
_fileEntry->setPath
|
_fileEntry->setPath
|
||||||
(util::applyDir
|
(util::applyDir
|
||||||
(getDownloadContext()->getDir(), httpResponse->determinFilename()));
|
(getDownloadContext()->getDir(),
|
||||||
|
util::fixTaintedBasename(httpResponse->determinFilename())));
|
||||||
}
|
}
|
||||||
_fileEntry->setContentType(httpResponse->getContentType());
|
_fileEntry->setContentType(httpResponse->getContentType());
|
||||||
_requestGroup->preDownloadProcessing();
|
_requestGroup->preDownloadProcessing();
|
||||||
|
|
|
@ -1011,6 +1011,12 @@ std::string applyDir(const std::string& dir, const std::string& relPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string fixTaintedBasename(const std::string& src)
|
||||||
|
{
|
||||||
|
return replace(replace(src, A2STR::SLASH_C, A2STR::UNDERSCORE_C),
|
||||||
|
A2STR::BACK_SLASH_C, A2STR::UNDERSCORE_C);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -362,6 +362,15 @@ bool saveAs
|
||||||
// dir = "/", relPath = "foo" => "/foo"
|
// dir = "/", relPath = "foo" => "/foo"
|
||||||
std::string applyDir(const std::string& dir, const std::string& relPath);
|
std::string applyDir(const std::string& dir, const std::string& relPath);
|
||||||
|
|
||||||
|
// In HTTP/FTP, file name is file component in URI. In HTTP, filename
|
||||||
|
// may be a value of Content-Disposition header. They are likely
|
||||||
|
// percent encoded. If they contains, for example, %2F, when decoded,
|
||||||
|
// basename contains dir component. This should be avoided. This
|
||||||
|
// function is created to fix these issues. This function expects src
|
||||||
|
// should be non-percent-encoded basename. Currently, this function
|
||||||
|
// replaces '/' and '\' with '_'.
|
||||||
|
std::string fixTaintedBasename(const std::string& src);
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -59,6 +59,7 @@ class UtilTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testFromHex);
|
CPPUNIT_TEST(testFromHex);
|
||||||
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
CPPUNIT_TEST(testParsePrioritizePieceRange);
|
||||||
CPPUNIT_TEST(testApplyDir);
|
CPPUNIT_TEST(testApplyDir);
|
||||||
|
CPPUNIT_TEST(testFixTaintedBasename);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -106,6 +107,7 @@ public:
|
||||||
void testFromHex();
|
void testFromHex();
|
||||||
void testParsePrioritizePieceRange();
|
void testParsePrioritizePieceRange();
|
||||||
void testApplyDir();
|
void testApplyDir();
|
||||||
|
void testFixTaintedBasename();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -910,4 +912,11 @@ void UtilTest::testApplyDir()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string("/dl/pred"), util::applyDir("/dl", "pred"));
|
CPPUNIT_ASSERT_EQUAL(std::string("/dl/pred"), util::applyDir("/dl", "pred"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilTest::testFixTaintedBasename()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("a_b"), util::fixTaintedBasename("a/b"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("a_b"), util::fixTaintedBasename("a\\b"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("a__b"), util::fixTaintedBasename("a\\/b"));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue