diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-05-03 12:23:31 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-05-11 19:11:19 -0500 |
commit | cd921db764df9578733c85c29e8c6c368f4c7e78 (patch) | |
tree | 8c04087da4430101afa9c065cc5c6555335d4b32 /src/burn/engine/container.cpp | |
parent | 67dd3ced3b383eb8423156cdabd3f9ce037caba8 (diff) | |
download | wix-cd921db764df9578733c85c29e8c6c368f4c7e78.tar.gz wix-cd921db764df9578733c85c29e8c6c368f4c7e78.tar.bz2 wix-cd921db764df9578733c85c29e8c6c368f4c7e78.zip |
Enforce payload and container verification.
Diffstat (limited to 'src/burn/engine/container.cpp')
-rw-r--r-- | src/burn/engine/container.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/burn/engine/container.cpp b/src/burn/engine/container.cpp index 0cce3131..c6f2ada8 100644 --- a/src/burn/engine/container.cpp +++ b/src/burn/engine/container.cpp | |||
@@ -50,16 +50,9 @@ extern "C" HRESULT ContainersParseFromXml( | |||
50 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pContainer->sczId); | 50 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pContainer->sczId); |
51 | ExitOnFailure(hr, "Failed to get @Id."); | 51 | ExitOnFailure(hr, "Failed to get @Id."); |
52 | 52 | ||
53 | // @Primary | ||
54 | hr = XmlGetYesNoAttribute(pixnNode, L"Primary", &pContainer->fPrimary); | ||
55 | if (E_NOTFOUND != hr) | ||
56 | { | ||
57 | ExitOnFailure(hr, "Failed to get @Primary."); | ||
58 | } | ||
59 | |||
60 | // @Attached | 53 | // @Attached |
61 | hr = XmlGetYesNoAttribute(pixnNode, L"Attached", &pContainer->fAttached); | 54 | hr = XmlGetYesNoAttribute(pixnNode, L"Attached", &pContainer->fAttached); |
62 | if (E_NOTFOUND != hr || pContainer->fPrimary) // if it is a primary container, it has to be attached | 55 | if (E_NOTFOUND != hr) |
63 | { | 56 | { |
64 | ExitOnFailure(hr, "Failed to get @Attached."); | 57 | ExitOnFailure(hr, "Failed to get @Attached."); |
65 | } | 58 | } |
@@ -87,10 +80,7 @@ extern "C" HRESULT ContainersParseFromXml( | |||
87 | { | 80 | { |
88 | // @FilePath | 81 | // @FilePath |
89 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pContainer->sczFilePath); | 82 | hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pContainer->sczFilePath); |
90 | if (E_NOTFOUND != hr) | 83 | ExitOnFailure(hr, "Failed to get @FilePath."); |
91 | { | ||
92 | ExitOnFailure(hr, "Failed to get @FilePath."); | ||
93 | } | ||
94 | } | 84 | } |
95 | 85 | ||
96 | // The source path starts as the file path. | 86 | // The source path starts as the file path. |
@@ -99,23 +89,32 @@ extern "C" HRESULT ContainersParseFromXml( | |||
99 | 89 | ||
100 | // @DownloadUrl | 90 | // @DownloadUrl |
101 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pContainer->downloadSource.sczUrl); | 91 | hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pContainer->downloadSource.sczUrl); |
102 | if (E_NOTFOUND != hr || (!pContainer->fPrimary && !pContainer->sczSourcePath)) // if the package is not a primary package, it must have a source path or a download url | 92 | if (E_NOTFOUND != hr) |
103 | { | 93 | { |
104 | ExitOnFailure(hr, "Failed to get @DownloadUrl. Either @SourcePath or @DownloadUrl needs to be provided."); | 94 | ExitOnFailure(hr, "Failed to get @DownloadUrl."); |
105 | } | 95 | } |
106 | 96 | ||
107 | // @Hash | 97 | // @Hash |
108 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &pContainer->sczHash); | 98 | hr = XmlGetAttributeEx(pixnNode, L"Hash", &pContainer->sczHash); |
109 | if (SUCCEEDED(hr)) | 99 | ExitOnFailure(hr, "Failed to get @Hash."); |
110 | { | 100 | |
111 | hr = StrAllocHexDecode(pContainer->sczHash, &pContainer->pbHash, &pContainer->cbHash); | 101 | hr = StrAllocHexDecode(pContainer->sczHash, &pContainer->pbHash, &pContainer->cbHash); |
112 | ExitOnFailure(hr, "Failed to hex decode the Container/@Hash."); | 102 | ExitOnFailure(hr, "Failed to hex decode the Container/@Hash."); |
113 | } | 103 | |
114 | else if (E_NOTFOUND != hr) | 104 | // @FileSize |
105 | hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz); | ||
106 | ExitOnFailure(hr, "Failed to get @FileSize."); | ||
107 | |||
108 | hr = StrStringToUInt64(scz, 0, &pContainer->qwFileSize); | ||
109 | ExitOnFailure(hr, "Failed to parse @FileSize."); | ||
110 | |||
111 | if (!pContainer->qwFileSize) | ||
115 | { | 112 | { |
116 | ExitOnFailure(hr, "Failed to get @Hash."); | 113 | ExitOnRootFailure(hr = E_INVALIDDATA, "File size is required when verifying by hash for container: %ls", pContainer->sczId); |
117 | } | 114 | } |
118 | 115 | ||
116 | pContainer->verification = BURN_CONTAINER_VERIFICATION_HASH; | ||
117 | |||
119 | // prepare next iteration | 118 | // prepare next iteration |
120 | ReleaseNullObject(pixnNode); | 119 | ReleaseNullObject(pixnNode); |
121 | } | 120 | } |
@@ -136,6 +135,7 @@ extern "C" HRESULT ContainersInitialize( | |||
136 | ) | 135 | ) |
137 | { | 136 | { |
138 | HRESULT hr = S_OK; | 137 | HRESULT hr = S_OK; |
138 | DWORD64 qwSize = 0; | ||
139 | 139 | ||
140 | if (pContainers->rgContainers) | 140 | if (pContainers->rgContainers) |
141 | { | 141 | { |
@@ -147,8 +147,13 @@ extern "C" HRESULT ContainersInitialize( | |||
147 | // manifest contained and get the offset to the container. | 147 | // manifest contained and get the offset to the container. |
148 | if (pContainer->fAttached) | 148 | if (pContainer->fAttached) |
149 | { | 149 | { |
150 | hr = SectionGetAttachedContainerInfo(pSection, pContainer->dwAttachedIndex, pContainer->type, &pContainer->qwAttachedOffset, &pContainer->qwFileSize, &pContainer->fActuallyAttached); | 150 | hr = SectionGetAttachedContainerInfo(pSection, pContainer->dwAttachedIndex, pContainer->type, &pContainer->qwAttachedOffset, &qwSize, &pContainer->fActuallyAttached); |
151 | ExitOnFailure(hr, "Failed to get attached container information."); | 151 | ExitOnFailure(hr, "Failed to get attached container information."); |
152 | |||
153 | if (qwSize != pContainer->qwFileSize) | ||
154 | { | ||
155 | ExitOnFailure(hr, "Attached container '%ls' size '%llu' didn't match size from manifest: '%llu'", pContainer->sczId, qwSize, pContainer->qwFileSize); | ||
156 | } | ||
152 | } | 157 | } |
153 | } | 158 | } |
154 | } | 159 | } |
@@ -195,7 +200,6 @@ extern "C" HRESULT ContainerOpenUX( | |||
195 | 200 | ||
196 | // open attached container | 201 | // open attached container |
197 | container.type = BURN_CONTAINER_TYPE_CABINET; | 202 | container.type = BURN_CONTAINER_TYPE_CABINET; |
198 | container.fPrimary = TRUE; | ||
199 | container.fAttached = TRUE; | 203 | container.fAttached = TRUE; |
200 | container.dwAttachedIndex = 0; | 204 | container.dwAttachedIndex = 0; |
201 | 205 | ||