Update payload.cpp and container.cpp to use more concise Exit* macros.
Sean Hall committed
May 26, 2022 at 17:34 UTC
a070d8c7b57d6c9a54106abeb359a6c868b6d7ae
2 files changed
+43
-54
src/burn/engine/container.cpp
+12
-20
@@ -15,6 +15,7 @@ extern "C" HRESULT ContainersParseFromXml(
15
IXMLDOMNode* pixnNode = NULL;
16
DWORD cNodes = 0;
17
LPWSTR scz = NULL;
18
+ BOOL fXmlFound = FALSE;
19
20
// select container nodes
21
hr = XmlSelectNodes(pixnBundle, L"Container", &pixnNodes);
@@ -48,26 +49,20 @@ extern "C" HRESULT ContainersParseFromXml(
49
50
// @Id
51
hr = XmlGetAttributeEx(pixnNode, L"Id", &pContainer->sczId);
51
- ExitOnFailure(hr, "Failed to get @Id.");
52
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Id.");
53
54
// @Attached
55
hr = XmlGetYesNoAttribute(pixnNode, L"Attached", &pContainer->fAttached);
55
- if (E_NOTFOUND != hr)
56
- {
57
- ExitOnFailure(hr, "Failed to get @Attached.");
58
- }
59
-
60
- // @AttachedIndex
61
- hr = XmlGetAttributeNumber(pixnNode, L"AttachedIndex", &pContainer->dwAttachedIndex);
62
- if (E_NOTFOUND != hr || pContainer->fAttached) // if it is an attached container it must have an index
63
- {
64
- ExitOnFailure(hr, "Failed to get @AttachedIndex.");
65
- }
56
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Attached.");
57
58
// Attached containers are always found attached to the current process, so use the current proccess's
59
// name instead of what may be in the manifest.
60
if (pContainer->fAttached)
61
{
62
+ // @AttachedIndex
63
+ hr = XmlGetAttributeNumber(pixnNode, L"AttachedIndex", &pContainer->dwAttachedIndex);
64
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @AttachedIndex.");
65
+
66
hr = PathForCurrentProcess(&scz, NULL);
67
ExitOnFailure(hr, "Failed to get path to current process for attached container.");
68
@@ -80,7 +75,7 @@ extern "C" HRESULT ContainersParseFromXml(
75
{
76
// @FilePath
77
hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pContainer->sczFilePath);
83
- ExitOnFailure(hr, "Failed to get @FilePath.");
78
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FilePath.");
79
}
80
81
// The source path starts as the file path.
@@ -89,28 +84,25 @@ extern "C" HRESULT ContainersParseFromXml(
84
85
// @DownloadUrl
86
hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pContainer->downloadSource.sczUrl);
92
- if (E_NOTFOUND != hr)
93
- {
94
- ExitOnFailure(hr, "Failed to get @DownloadUrl.");
95
- }
87
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @DownloadUrl.");
88
89
// @Hash
90
hr = XmlGetAttributeEx(pixnNode, L"Hash", &pContainer->sczHash);
99
- ExitOnFailure(hr, "Failed to get @Hash.");
91
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Hash.");
92
93
hr = StrAllocHexDecode(pContainer->sczHash, &pContainer->pbHash, &pContainer->cbHash);
94
ExitOnFailure(hr, "Failed to hex decode the Container/@Hash.");
95
96
// @FileSize
97
hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz);
106
- ExitOnFailure(hr, "Failed to get @FileSize.");
98
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FileSize.");
99
100
hr = StrStringToUInt64(scz, 0, &pContainer->qwFileSize);
101
ExitOnFailure(hr, "Failed to parse @FileSize.");
102
103
if (!pContainer->qwFileSize)
104
{
113
- ExitOnRootFailure(hr = E_INVALIDDATA, "File size is required when verifying by hash for container: %ls", pContainer->sczId);
105
+ ExitWithRootFailure(hr, E_INVALIDDATA, "File size is required when verifying by hash for container: %ls", pContainer->sczId);
106
}
107
108
pContainer->verification = BURN_CONTAINER_VERIFICATION_HASH;
src/burn/engine/payload.cpp
+31
-34
@@ -23,6 +23,7 @@ extern "C" HRESULT PayloadsParseFromXml(
23
BOOL fChainPayload = pContainers && pLayoutPayloads; // These are required when parsing chain payloads.
24
BOOL fValidFileSize = FALSE;
25
size_t cByteOffset = fChainPayload ? offsetof(BURN_PAYLOAD, sczKey) : offsetof(BURN_PAYLOAD, sczSourcePath);
26
+ BOOL fXmlFound = FALSE;
27
28
// select payload nodes
29
hr = XmlSelectNodes(pixnBundle, L"Payload", &pixnNodes);
@@ -58,15 +59,15 @@ extern "C" HRESULT PayloadsParseFromXml(
59
60
// @Id
61
hr = XmlGetAttributeEx(pixnNode, L"Id", &pPayload->sczKey);
61
- ExitOnFailure(hr, "Failed to get @Id.");
62
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Id.");
63
64
// @FilePath
65
hr = XmlGetAttributeEx(pixnNode, L"FilePath", &pPayload->sczFilePath);
65
- ExitOnFailure(hr, "Failed to get @FilePath.");
66
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @FilePath.");
67
68
// @SourcePath
69
hr = XmlGetAttributeEx(pixnNode, L"SourcePath", &pPayload->sczSourcePath);
69
- ExitOnFailure(hr, "Failed to get @SourcePath.");
70
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @SourcePath.");
71
72
if (!fChainPayload)
73
{
@@ -77,7 +78,7 @@ extern "C" HRESULT PayloadsParseFromXml(
78
{
79
// @Packaging
80
hr = XmlGetAttributeEx(pixnNode, L"Packaging", &scz);
80
- ExitOnFailure(hr, "Failed to get @Packaging.");
81
+ ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Packaging.");
82
83
if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"embedded", -1))
84
{
@@ -89,43 +90,40 @@ extern "C" HRESULT PayloadsParseFromXml(
90
}
91
else
92
{
92
- hr = E_INVALIDARG;
93
- ExitOnFailure(hr, "Invalid value for @Packaging: %ls", scz);
93
+ ExitWithRootFailure(hr, E_INVALIDARG, "Invalid value for @Packaging: %ls", scz);
94
}
95
96
// @Container
97
hr = XmlGetAttributeEx(pixnNode, L"Container", &scz);
98
- if (E_NOTFOUND != hr || BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging)
99
- {
100
- ExitOnFailure(hr, "Failed to get @Container.");
98
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Container.");
99
100
+ if (fXmlFound)
101
+ {
102
// find container
103
hr = ContainerFindById(pContainers, scz, &pPayload->pContainer);
104
- ExitOnFailure(hr, "Failed to to find container: %ls", scz);
104
+ ExitOnFailure(hr, "Failed to find container: %ls", scz);
105
106
pPayload->pContainer->cParsedPayloads += 1;
107
}
108
+ else if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging)
109
+ {
110
+ ExitWithRootFailure(hr, E_NOTFOUND, "@Container is required for embedded payload.");
111
+ }
112
113
// @LayoutOnly
114
hr = XmlGetYesNoAttribute(pixnNode, L"LayoutOnly", &pPayload->fLayoutOnly);
111
- if (E_NOTFOUND != hr)
112
- {
113
- ExitOnFailure(hr, "Failed to get @LayoutOnly.");
114
- }
115
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @LayoutOnly.");
116
117
// @DownloadUrl
118
hr = XmlGetAttributeEx(pixnNode, L"DownloadUrl", &pPayload->downloadSource.sczUrl);
118
- if (E_NOTFOUND != hr)
119
- {
120
- ExitOnFailure(hr, "Failed to get @DownloadUrl.");
121
- }
119
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @DownloadUrl.");
120
121
// @FileSize
122
hr = XmlGetAttributeEx(pixnNode, L"FileSize", &scz);
125
- if (E_NOTFOUND != hr)
126
- {
127
- ExitOnFailure(hr, "Failed to get @FileSize.");
123
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @FileSize.");
124
125
+ if (fXmlFound)
126
+ {
127
hr = StrStringToUInt64(scz, 0, &pPayload->qwFileSize);
128
ExitOnFailure(hr, "Failed to parse @FileSize.");
129
@@ -134,10 +132,10 @@ extern "C" HRESULT PayloadsParseFromXml(
132
133
// @CertificateAuthorityKeyIdentifier
134
hr = XmlGetAttributeEx(pixnNode, L"CertificateRootPublicKeyIdentifier", &scz);
137
- if (E_NOTFOUND != hr)
138
- {
139
- ExitOnFailure(hr, "Failed to get @CertificateRootPublicKeyIdentifier.");
135
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @CertificateRootPublicKeyIdentifier.");
136
137
+ if (fXmlFound)
138
+ {
139
hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootPublicKeyIdentifier, &pPayload->cbCertificateRootPublicKeyIdentifier);
140
ExitOnFailure(hr, "Failed to hex decode @CertificateRootPublicKeyIdentifier.");
141
@@ -146,20 +144,20 @@ extern "C" HRESULT PayloadsParseFromXml(
144
145
// @CertificateThumbprint
146
hr = XmlGetAttributeEx(pixnNode, L"CertificateRootThumbprint", &scz);
149
- if (E_NOTFOUND != hr)
150
- {
151
- ExitOnFailure(hr, "Failed to get @CertificateRootThumbprint.");
147
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @CertificateRootThumbprint.");
148
149
+ if (fXmlFound)
150
+ {
151
hr = StrAllocHexDecode(scz, &pPayload->pbCertificateRootThumbprint, &pPayload->cbCertificateRootThumbprint);
152
ExitOnFailure(hr, "Failed to hex decode @CertificateRootThumbprint.");
153
}
154
155
// @Hash
156
hr = XmlGetAttributeEx(pixnNode, L"Hash", &scz);
159
- if (E_NOTFOUND != hr)
160
- {
161
- ExitOnFailure(hr, "Failed to get @Hash.");
157
+ ExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get @Hash.");
158
159
+ if (fXmlFound)
160
+ {
161
hr = StrAllocHexDecode(scz, &pPayload->pbHash, &pPayload->cbHash);
162
ExitOnFailure(hr, "Failed to hex decode the Payload/@Hash.");
163
@@ -171,11 +169,11 @@ extern "C" HRESULT PayloadsParseFromXml(
169
170
if (BURN_PAYLOAD_VERIFICATION_NONE == pPayload->verification)
171
{
174
- ExitOnRootFailure(hr = E_INVALIDDATA, "There was no verification information for payload: %ls", pPayload->sczKey);
172
+ ExitWithRootFailure(hr, E_INVALIDDATA, "There was no verification information for payload: %ls", pPayload->sczKey);
173
}
174
else if (BURN_PAYLOAD_VERIFICATION_HASH == pPayload->verification && !fValidFileSize)
175
{
178
- ExitOnRootFailure(hr = E_INVALIDDATA, "File size is required when verifying by hash for payload: %ls", pPayload->sczKey);
176
+ ExitWithRootFailure(hr, E_INVALIDDATA, "File size is required when verifying by hash for payload: %ls", pPayload->sczKey);
177
}
178
179
if (pPayload->fLayoutOnly)
@@ -321,8 +319,7 @@ extern "C" HRESULT PayloadExtractUXContainer(
319
// if the payload has not been acquired
320
if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state)
321
{
324
- hr = E_INVALIDDATA;
325
- ExitOnRootFailure(hr, "Payload was not found in container: %ls", pPayload->sczKey);
322
+ ExitWithRootFailure(hr, E_INVALIDDATA, "Payload was not found in container: %ls", pPayload->sczKey);
323
}
324
}
325