Skip to content

Commit 494646b

Browse files
[packchk] Validate <url> starts with https:// #1109 (#1140)
* [packchk] Validate <url> starts with https:// #1109
1 parent 200d967 commit 494646b

File tree

5 files changed

+128
-2
lines changed

5 files changed

+128
-2
lines changed

tools/packchk/include/CheckFiles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CheckFiles {
3030
void SetPackagePath(const std::string& packagePath);
3131
const std::string& GetPackagePath() const;
3232
bool CheckFile(RteItem* item);
33+
bool CheckUrls(RteItem* item);
3334
bool CheckFileExists(const std::string& fileName, int lineNo, bool associated = false);
3435
bool CheckCaseSense(const std::string& fileName, int lineNo);
3536
bool CheckFileIsInPack(const std::string& fileName, int lineNo);

tools/packchk/src/CheckFiles.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CheckFilesVisitor::~CheckFilesVisitor()
4040
VISIT_RESULT CheckFilesVisitor::Visit(RteItem* item)
4141
{
4242
m_checkFiles.CheckFile(item);
43+
m_checkFiles.CheckUrls(item);
4344

4445
return VISIT_RESULT::CONTINUE_VISIT;
4546
}
@@ -164,6 +165,36 @@ bool CheckFiles::ToUpper(string& text)
164165
return true;
165166
}
166167

168+
/**
169+
* @brief check aspects of an RTE url item
170+
* @param item RteItem item to check
171+
* @return passed / failed
172+
*/
173+
bool CheckFiles::CheckUrls(RteItem* item)
174+
{
175+
if(!item || item->GetTag() == "package") {
176+
return true;
177+
}
178+
179+
bool bOk = true;
180+
const auto lineNo = item->GetLineNumber();
181+
182+
if(item->GetText().find("http://", 0) != string::npos) {
183+
LogMsg("M368", TAG(item->GetTag()), URL("https://"), lineNo);
184+
bOk = false;
185+
}
186+
187+
const auto& attributes = item->GetAttributes();
188+
for(const auto& [attr, text] : attributes) {
189+
if(text.find("http://", 0) != string::npos) {
190+
LogMsg("M368", TAG(attr), URL("https://"), lineNo);
191+
bOk = false;
192+
}
193+
}
194+
195+
return bOk;
196+
}
197+
167198
/**
168199
* @brief check aspects of an RTE file item
169200
* @param item RteItem item to check

tools/packchk/src/PackChk_Msgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const MsgTable PackChk::msgTable = {
184184
{ "M365", { MsgLevel::LEVEL_ERROR, CRLF_B, "Redefined %DEVTYPE% '%MCU%' found, see Line %LINE%" } },
185185
{ "M366", { MsgLevel::LEVEL_ERROR, CRLF_B, "Redefined %DEVTYPEEXIST% as %DEVTYPE% '%MCU%' found, see Line %LINE%" } },
186186
{ "M367", { MsgLevel::LEVEL_ERROR, CRLF_B, "Redefined %TYPE% '%NAME%' found, see Line %LINE%" } },
187-
{ "M368", { MsgLevel::LEVEL_ERROR, CRLF_B, "" } },
187+
{ "M368", { MsgLevel::LEVEL_WARNING, CRLF_B, "%TAG% must use '%URL%'" } },
188188
{ "M369", { MsgLevel::LEVEL_WARNING3, CRLF_B, "Feature is already defined for '%MCU%' and will be added, see Line %LINE%: '%PROP%'" } },
189189
{ "M370", { MsgLevel::LEVEL_WARNING, CRLF_B, "URL is not conformant: '%URL%':\n Backslashes are not allowed in URL, use forward slashes." } },
190190
{ "M371", { MsgLevel::LEVEL_ERROR, CRLF_B, "%SECTION% Feature for '%MCU%': '%FEATURE%' unknown." } },
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<package schemaVersion="1.4" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="PACK.xsd">
4+
<vendor>TestVendor</vendor>
5+
<url>http://www.testurl.foo/pack/</url>
6+
<name>TestUrlHttps</name>
7+
<description>TestUrlHttps</description>
8+
<repository type="git">http://github.com/ARM-software/CMSIS-Driver.git</repository>
9+
10+
<releases>
11+
<release version="2.1.0" date="2022-06-19" tag="2.1.0" url="http://github.com/ARM-software/CMSIS-Driver/archive/2.1.0.zip">
12+
Added nothing.
13+
</release>
14+
<release version="0.0.1" date="2022-06-20">
15+
Initial release of TestUrlHttps.
16+
</release>
17+
</releases>
18+
19+
<keywords>
20+
<keyword>TestUrlHttps</keyword>
21+
</keywords>
22+
23+
<conditions>
24+
<condition id="Test_Condition">
25+
<description>Test Device</description>
26+
<require Dvendor="ARM:82"/>
27+
</condition>
28+
</conditions>
29+
30+
<components>
31+
<component Cclass="TestClass" Cgroup="TestGlobal" Cversion="1.0.0" condition="Test_Condition">
32+
<description>TestGlobal</description>
33+
</component>
34+
<component Cclass="Device" Cgroup="Config Tools" Csub="Init" Cversion="1.0.0" condition="Test_Condition" generator="MyConfig">
35+
<description>Initialization generated by MyConfig</description>
36+
<files>
37+
<file category="doc" name="http://www.testurl.foo/web/myConfig"/>
38+
</files>
39+
</component>
40+
</components>
41+
42+
<devices>
43+
<family Dfamily="MyDevice Series" Dvendor="MyDevice:99">
44+
<processor Dcore="Cortex-M3" DcoreVersion="r1p1"/>
45+
<book category="overview" name="http://www.testurl.foo/web/myDevice" title="MyDevice Web Page"/>
46+
47+
<subFamily DsubFamily="MyDevice">
48+
<device Dname="MyDeviceM0">
49+
<processor Dfpu="0" Dmpu="0" Dendian="Little-endian" Dclock="24000000"/>
50+
</device>
51+
</subFamily>
52+
</family>
53+
</devices>
54+
55+
<boards>
56+
<board vendor="ARM" name="MyBoard" orderForm="http://www.testurl.foo">
57+
<description>MyBoard Evaluation Kit</description>
58+
<image small="http://www.testurl.foo/web/myBoardSmall.png"/>
59+
<book category="overview" name="http://www.testurl.foo/web/myBoard" title="MyBoard" public="true"/>
60+
</board>
61+
</boards>
62+
63+
</package>

tools/packchk/test/integtests/src/PackChkIntegTests.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,38 @@ TEST_F(PackChkIntegTests, CheckDuplicateFlashAlgo) {
753753
}
754754
}
755755

756+
757+
// Validate URLs to start with 'https://'
758+
TEST_F(PackChkIntegTests, CheckUrlForHttp) {
759+
const char* argv[5];
760+
761+
const string& pdscFile = PackChkIntegTestEnv::localtestdata_dir +
762+
"/TestUrlHttps/TestVendor.TestUrlHttps.pdsc";
763+
ASSERT_TRUE(RteFsUtils::Exists(pdscFile));
764+
765+
argv[0] = (char*)"";
766+
argv[1] = (char*)pdscFile.c_str();
767+
argv[2] = (char*)"--disable-validation";
768+
argv[3] = (char*)"-x";
769+
argv[4] = (char*)"!M368";
770+
771+
PackChk packChk;
772+
EXPECT_EQ(1, packChk.Check(2, argv, nullptr));
773+
774+
auto errMsgs = ErrLog::Get()->GetLogMessages();
775+
int M368_foundCnt = 0;
776+
for (const string& msg : errMsgs) {
777+
size_t s;
778+
if ((s = msg.find("M368")) != string::npos) {
779+
M368_foundCnt++;
780+
}
781+
}
782+
783+
if (M368_foundCnt != 8) {
784+
FAIL() << "error: missing message M368";
785+
}
786+
}
787+
756788
// Validate invalid file path (file is directory)
757789
TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
758790
const char* argv[3];
@@ -782,7 +814,6 @@ TEST_F(PackChkIntegTests, CheckConfigFileInIncludePath) {
782814
}
783815
}
784816

785-
786817
// Test schema validation
787818
TEST_F(PackChkIntegTests, CheckSchemaValidation) {
788819
const char* argv[3];

0 commit comments

Comments
 (0)