Skip to content

Commit ff06a49

Browse files
parsodarkPierrick Arsenaultericwolz
authored
Fix HTTPAPIEX_ExecuteRequest failing with HTTPAPI_REQUEST_HEAD (#528)
The HTTPAPI_REQUEST_TYPE enum is defined using the MU_DEFINE_ENUM macro, which implicitely adds HTTPAPI_REQUEST_TYPE_INVALID as the first value. This makes checking the validity of requestType with MU_COUNT_ARG incorrect: HTTPAPI_REQUEST_TYPE_INVALID is accepted and HTTPAPI_REQUEST_HEAD is rejected. Unit tests: - Change all uses of HTTPAPI_REQUEST_PATCH (the previous last value in the enum) to HTTPAPI_REQUEST_HEAD (the current last value in the enum) to test that it is accepted. - Change HTTPAPIEX_ExecuteRequest_fails_with_invalid_request_type to use a request type outside of the enum. - Add HTTPAPIEX_ExecuteRequest_fails_with_invalid_request_type_2, which explicitely tests that HTTPAPIEX_INVALID_ARG is rejected. Co-authored-by: Pierrick Arsenault <[email protected]> Co-authored-by: Eric Wolz <[email protected]>
1 parent fb2c745 commit ff06a49

File tree

2 files changed

+121
-79
lines changed

2 files changed

+121
-79
lines changed

src/httpapiex.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,27 @@ static int buildAllRequests(HTTPAPIEX_HANDLE_DATA* handle, HTTPAPI_REQUEST_TYPE
336336
return result;
337337
}
338338

339+
static bool validRequestType(HTTPAPI_REQUEST_TYPE requestType)
340+
{
341+
bool result;
342+
343+
if ((requestType == HTTPAPI_REQUEST_GET) ||
344+
(requestType == HTTPAPI_REQUEST_POST) ||
345+
(requestType == HTTPAPI_REQUEST_PUT) ||
346+
(requestType == HTTPAPI_REQUEST_DELETE) ||
347+
(requestType == HTTPAPI_REQUEST_PATCH) ||
348+
(requestType == HTTPAPI_REQUEST_HEAD))
349+
{
350+
result = true;
351+
}
352+
else
353+
{
354+
result = false;
355+
}
356+
357+
return result;
358+
}
359+
339360
HTTPAPIEX_RESULT HTTPAPIEX_ExecuteRequest(HTTPAPIEX_HANDLE handle, HTTPAPI_REQUEST_TYPE requestType, const char* relativePath,
340361
HTTP_HEADERS_HANDLE requestHttpHeadersHandle, BUFFER_HANDLE requestContent, unsigned int* statusCode,
341362
HTTP_HEADERS_HANDLE responseHttpHeadersHandle, BUFFER_HANDLE responseContent)
@@ -350,7 +371,7 @@ HTTPAPIEX_RESULT HTTPAPIEX_ExecuteRequest(HTTPAPIEX_HANDLE handle, HTTPAPI_REQUE
350371
else
351372
{
352373
/*Codes_SRS_HTTPAPIEX_02_007: [If parameter requestType does not indicate a valid request, HTTPAPIEX_ExecuteRequest shall fail and return HTTPAPIEX_INVALID_ARG.] */
353-
if (requestType >= MU_COUNT_ARG(HTTPAPI_REQUEST_TYPE_VALUES))
374+
if (!validRequestType(requestType))
354375
{
355376
result = HTTPAPIEX_INVALID_ARG;
356377
LOG_HTTAPIEX_ERROR();

0 commit comments

Comments
 (0)