MdeModulePkg:DxeHttpLib: Add checks in HttpGenRequestMessage API

HttpGenRequestMessage assumes that HTTP message would always
contain a request-line, headers and an optional message body.
However, subsequent to a HTTP PUT/POST request, HTTP requests
would contain just the message body. This patch supports
creation of such request messages with additional checks.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hegde, Nagaraj P <nagaraj-p.hegde@hpe.com>
Reviewed-By: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
This commit is contained in:
Nagaraj Hegde 2016-05-05 14:59:03 +08:00 committed by Fu Siyuan
parent 0c986eafae
commit 09991304c9
1 changed files with 124 additions and 89 deletions

View File

@ -1680,6 +1680,20 @@ HttpGenRequestMessage (
AppendList = NULL;
HttpUtilitiesProtocol = NULL;
//
// 1. If we have a Request, we cannot have a NULL Url
// 2. If we have a Request, HeaderCount can not be non-zero
// 3. If we do not have a Request, HeaderCount should be zero
// 4. If we do not have Request and Headers, we need at least a message-body
//
if ((Message->Data.Request != NULL && Url == NULL) ||
(Message->Data.Request != NULL && Message->HeaderCount == 0) ||
(Message->Data.Request == NULL && Message->HeaderCount != 0) ||
(Message->Data.Request == NULL && Message->HeaderCount == 0 && Message->BodyLength == 0)) {
return EFI_INVALID_PARAMETER;
}
if (Message->HeaderCount != 0) {
//
// Locate the HTTP_UTILITIES protocol.
//
@ -1728,14 +1742,31 @@ HttpGenRequestMessage (
if (EFI_ERROR (Status) || HttpHdr == NULL){
return Status;
}
}
//
// Calculate HTTP message length.
// If we have headers to be sent, account for it.
//
MsgSize = Message->BodyLength + HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (Url) +
AsciiStrLen (HTTP_VERSION_CRLF_STR) + HttpHdrSize;
if (Message->HeaderCount != 0) {
MsgSize = HttpHdrSize;
}
//
// If we have a request line, account for the fields.
//
if (Message->Data.Request != NULL) {
MsgSize += HTTP_METHOD_MAXIMUM_LEN + AsciiStrLen (HTTP_VERSION_CRLF_STR) + AsciiStrLen (Url);
}
//
// If we have a message body to be sent, account for it.
//
MsgSize += Message->BodyLength;
//
// memory for the string that needs to be sent to TCP
//
*RequestMsg = AllocateZeroPool (MsgSize);
if (*RequestMsg == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@ -1746,6 +1777,7 @@ HttpGenRequestMessage (
//
// Construct header request
//
if (Message->Data.Request != NULL) {
switch (Message->Data.Request->Method) {
case HttpMethodGet:
StrLength = sizeof (HTTP_METHOD_GET) - 1;
@ -1795,11 +1827,14 @@ HttpGenRequestMessage (
CopyMem (RequestPtr, HTTP_VERSION_CRLF_STR, StrLength);
RequestPtr += StrLength;
if (HttpHdr != NULL) {
//
// Construct header
//
CopyMem (RequestPtr, HttpHdr, HttpHdrSize);
RequestPtr += HttpHdrSize;
}
}
//
// Construct body