summaryrefslogtreecommitdiff
path: root/http_headers.h
diff options
context:
space:
mode:
Diffstat (limited to 'http_headers.h')
-rw-r--r--http_headers.h32
1 files changed, 16 insertions, 16 deletions
diff --git a/http_headers.h b/http_headers.h
index d8171e8..3503bf1 100644
--- a/http_headers.h
+++ b/http_headers.h
@@ -2,57 +2,57 @@
#define REQ_READ_ERROR -1
int get_request_data( http_request_data_t *hdt, char *req_contents ){
- if ( req_contents == NULL || (uint64_t)strlen(req_contents) <= 0 )
+ if ( req_contents == NULL || (size_t)strnlen(req_contents, (size_t)MAX_RECV_BYTES) <= 0 )
return REQ_READ_ERROR;
- hdt->request_size = (size_t)strlen( req_contents );
+ hdt->request_size = (size_t)strnlen( req_contents, MAX_RECV_BYTES );
hdt->request_copy = (char*)calloc( hdt->request_size, sizeof(char) );
if ( hdt->request_copy == NULL )
return REQ_READ_ERROR;
strncpy( hdt->request_copy, req_contents, hdt->request_size );
- if ( (size_t)strlen(hdt->request_copy) != hdt->request_size )
+ if ( (size_t)strnlen(hdt->request_copy, (size_t)MAX_RECV_BYTES) != hdt->request_size )
return REQ_READ_ERROR;
hdt->tok_current = strtok_r( hdt->request_copy, "\r\n", &hdt->tok_prev );
- if ( hdt->tok_current == NULL || (uint64_t)strlen(hdt->tok_current) >= MAX_HEADER_LENGTH )
+ if ( hdt->tok_current == NULL || (size_t)strnlen(hdt->tok_current, (size_t)(MAX_HEADER_LENGTH + 1)) > (size_t)MAX_HEADER_LENGTH )
return REQ_READ_ERROR;
if ( strstr(hdt->tok_current, "GET /") == NULL && strstr(hdt->tok_current, "POST /") == NULL )
return REQ_READ_ERROR;
hdt->tok_current = strtok_r( hdt->request_copy, " ", &hdt->tok_prev );
if ( hdt->tok_current == NULL )
return REQ_READ_ERROR;
- hdt->request_method = (char*)calloc( (size_t)strlen(hdt->tok_current), sizeof(char) );
+ hdt->request_method = (char*)calloc( (size_t)strnlen(hdt->tok_current, (size_t)MAX_HEADER_LENGTH), sizeof(char) );
if ( hdt->request_method == NULL )
return REQ_READ_ERROR;
- strncpy( hdt->request_method, hdt->tok_current, (size_t)strlen(hdt->tok_current) );
- if ( (size_t)strlen(hdt->request_method) != (size_t)strlen(hdt->tok_current) )
+ strncpy( hdt->request_method, hdt->tok_current, (size_t)strnlen(hdt->tok_current, (size_t)MAX_HEADER_LENGTH) );
+ if ( (size_t)strnlen(hdt->request_method, MAX_HEADER_LENGTH) != (size_t)strnlen(hdt->tok_current, (size_t)(MAX_HEADER_LENGTH + 1)) )
return REQ_READ_ERROR;
hdt->tok_current = strtok_r( NULL, " ", &hdt->tok_prev );
if ( hdt->tok_current == NULL )
return REQ_READ_ERROR;
- hdt->request_path = (char*)calloc( (size_t)strlen(hdt->tok_current), sizeof(char) );
+ hdt->request_path = (char*)calloc( (size_t)strnlen(hdt->tok_current, (size_t)MAX_HEADER_LENGTH), sizeof(char) );
if ( hdt->request_path == NULL )
return REQ_READ_ERROR;
- strncpy( hdt->request_path, hdt->tok_current, (size_t)strlen(hdt->tok_current) );
- if ( (size_t)strlen(hdt->request_path) != (size_t)strlen(hdt->tok_current) )
+ strncpy( hdt->request_path, hdt->tok_current, (size_t)strnlen(hdt->tok_current, (size_t)MAX_HEADER_LENGTH) );
+ if ( (size_t)strnlen(hdt->request_path, (size_t)MAX_HEADER_LENGTH) != (size_t)strnlen(hdt->tok_current, (size_t)(MAX_HEADER_LENGTH + 1)) )
return REQ_READ_ERROR;
memset( hdt->request_copy, 0, hdt->request_size );
strncpy( hdt->request_copy, req_contents, hdt->request_size );
- if ( (size_t)strlen(hdt->request_copy) != hdt->request_size )
+ if ( (size_t)strnlen(hdt->request_copy, (size_t)(MAX_RECV_BYTES + 1)) != hdt->request_size )
return REQ_READ_ERROR;
char *request_body_begin = strstr( hdt->request_copy, "\r\n\r\n" );
- if ( request_body_begin == NULL || (uint64_t)strlen(request_body_begin) >= MAX_CONTENT_LENGTH ){
+ if ( request_body_begin == NULL || (size_t)strnlen(request_body_begin, (size_t)(MAX_CONTENT_LENGTH + 1)) > (size_t)MAX_CONTENT_LENGTH ){
hdt->request_body = NULL;
return REQ_READ_SUCCESS;
}
hdt->tok_current = strtok_r( request_body_begin, "\r\n\r\n", &hdt->tok_prev );
- if ( hdt->tok_current == NULL || (uint64_t)strlen(hdt->tok_current) >= MAX_CONTENT_LENGTH ){
+ if ( hdt->tok_current == NULL || (size_t)strnlen(hdt->tok_current, (size_t)(MAX_CONTENT_LENGTH + 1)) > (size_t)MAX_CONTENT_LENGTH ){
hdt->request_body = NULL;
return REQ_READ_SUCCESS;
}
- hdt->request_body = (char*)calloc( (size_t)strlen(hdt->tok_current), sizeof(char) );
+ hdt->request_body = (char*)calloc( (size_t)strnlen(hdt->tok_current, (size_t)MAX_CONTENT_LENGTH), sizeof(char) );
if ( hdt->request_body == NULL )
return REQ_READ_ERROR;
- strncpy( hdt->request_body, hdt->tok_current, (size_t)strlen(hdt->tok_current) );
- if ( (size_t)strlen(hdt->request_body) != (size_t)strlen(hdt->tok_current) )
+ strncpy( hdt->request_body, hdt->tok_current, (size_t)strnlen(hdt->tok_current, (size_t)MAX_CONTENT_LENGTH) );
+ if ( (size_t)strnlen(hdt->request_body, (size_t)MAX_CONTENT_LENGTH) != (size_t)strnlen(hdt->tok_current, (size_t)(MAX_CONTENT_LENGTH + 1)) )
return REQ_READ_ERROR;
return REQ_READ_SUCCESS;
}