Skip to content

Commit

Permalink
Merge pull request #10 from weston-embedded/bugfix/issue-6
Browse files Browse the repository at this point in the history
Added a nullity check for '.FormCfgPtr' and '.FormBoundaryPtr' in HTT…
  • Loading branch information
wes-jmagasrevy authored May 13, 2021
2 parents 526dc17 + d2a43d9 commit 422babc
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions Server/Source/http-s_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ static void HTTPsReq_HdrParse (HTTPs_INSTANCE *p_instance,
p_field_end,
&len);
if (p_val != DEF_NULL) {
len = p_field_end - p_val;
len = p_field_end - p_val;
/* Get content type key by comparing field val name. */
field_key = HTTP_Dict_KeyGet(HTTP_Dict_ContentType,
HTTP_Dict_ContentTypeSize,
Expand Down Expand Up @@ -1629,45 +1629,49 @@ static void HTTPsReq_HdrParse (HTTPs_INSTANCE *p_instance,
(HTTPs_CFG_FORM_MULTIPART_EN == DEF_ENABLED))
/* ----------------- STO BOUNDARY VAL ----------------- */
/* Boundary should be located after content type ... */
/* val (see Note #3b). */
/* ... val (see Note #3b). */

if ((p_cfg->FormCfgPtr != DEF_NULL) &&
(p_conn->FormBoundaryPtr != DEF_NULL)) {
/* Find end of content type val. */
p_dictionary = HTTP_Dict_EntryGet(HTTP_Dict_ContentType,
HTTP_Dict_ContentTypeSize,
HTTP_CONTENT_TYPE_MULTIPART_FORM);
p_val = p_val + p_dictionary->StrLen + 1;
p_val = HTTP_StrGraphSrchFirst(p_val, len);
len = len - (p_val - p_field);
p_dictionary = HTTP_Dict_EntryGet(HTTP_Dict_ContentType,
HTTP_Dict_ContentTypeSize,
HTTP_CONTENT_TYPE_MULTIPART_FORM);
p_val = p_val + p_dictionary->StrLen + 1;
p_val = HTTP_StrGraphSrchFirst(p_val, len);
len = len - (p_val - p_field);

/* Find beginning of boundary token. */
p_val = Str_Str_N(p_val,
HTTP_STR_MULTIPART_BOUNDARY,
sizeof(HTTP_STR_MULTIPART_BOUNDARY));
p_val = Str_Str_N(p_val,
HTTP_STR_MULTIPART_BOUNDARY,
sizeof(HTTP_STR_MULTIPART_BOUNDARY));

if (p_val == DEF_NULL) {
*p_err = HTTPs_ERR_REQ_FORMAT_INVALID;
return;
}
if (p_val == DEF_NULL) {
*p_err = HTTPs_ERR_REQ_FORMAT_INVALID;
return;
}

/* Boundary located after '='. */
p_val = Str_Char_N(p_val, len, ASCII_CHAR_EQUALS_SIGN);
if (p_val == DEF_NULL) {
*p_err = HTTPs_ERR_REQ_FORMAT_INVALID;
return;
}
p_val = Str_Char_N(p_val, len, ASCII_CHAR_EQUALS_SIGN);
if (p_val == DEF_NULL) {
*p_err = HTTPs_ERR_REQ_FORMAT_INVALID;
return;
}

p_val++; /* Remove space before boundary val. */
p_val = HTTP_StrGraphSrchFirst(p_val,
len);
len = p_field_end - p_val;
p_val++; /* Remove space before boundary val. */
p_val = HTTP_StrGraphSrchFirst(p_val,
len);
len = p_field_end - p_val;

/* Copy boundary val to Conn struct. */
Str_Copy_N(p_conn->FormBoundaryPtr,
p_val,
len);
Str_Copy_N(p_conn->FormBoundaryPtr,
p_val,
len);
/* Make sure to create a string. */
p_conn->FormBoundaryPtr[len] = ASCII_CHAR_NULL;
p_conn->FormBoundaryPtr[len] = ASCII_CHAR_NULL;

p_conn->FormBoundaryLen = len;
p_conn->FormBoundaryLen = len;
}
#endif
break;

Expand Down

0 comments on commit 422babc

Please sign in to comment.