pnoltes commented on code in PR #853:
URL: https://github.com/apache/celix/pull/853#discussion_r4579851008
##########
bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi_constants.h:
##########
@@ -79,5 +79,19 @@
*/
#define CELIX_RSA_DFI_DYNAMIC_IP_SUPPORT_DEFAULT false
+/**
+ * @brief Remote Service Admin DFI environment property (named
"CELIX_RSA_DFI_MAX_REQUEST_SIZE") which specifies
+ * the maximum accepted HTTP request body size in bytes. Requests with a
larger body are rejected with a
Review Comment:
Should this be configurable in bytes? I would expect al uses cases want as
mac request size at least 1 MB.
I think it would be better to rename this to
`CELIX_RSA_DFI_MAX_REQUEST_SIZE_IN_MB` and set the default to `16`.
##########
bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c:
##########
@@ -526,41 +544,59 @@ static int remoteServiceAdmin_callback(struct
mg_connection *conn) {
if (export != NULL) {
- uint64_t datalength = request_info->content_length;
- char* data = malloc(datalength + 1);
- mg_read(conn, data, datalength);
- data[datalength] = '\0';
-
- char *response = NULL;
- int responceLength = 0;
- int rc = exportRegistration_call(export, data, -1, &metadata,
&response, &responceLength);
- if (rc != CELIX_SUCCESS) {
- RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got
error %i\n", rc);
+ int64_t contentLength = request_info->content_length;
+ bool bodyRead = false;
+ char *data = NULL;
+
+ if (contentLength < 0 || (uint64_t)contentLength >
rsa->maxRequestSize) {
+ RSA_LOG_WARNING(rsa, "Rejecting request with invalid or too
large body (content length %lld, max %zu)", (long long)contentLength,
rsa->maxRequestSize);
+ mg_write(conn, request_too_large_response_headers,
strlen(request_too_large_response_headers));
+ } else if ((data = malloc((size_t)contentLength + 1)) == NULL) {
+ RSA_LOG_ERROR(rsa, "Error allocating memory for request body
of %zu bytes", (size_t)contentLength);
+ mg_write(conn, internal_error_response_headers,
strlen(internal_error_response_headers));
+ } else {
+ int nrOfBytesRead = mg_read(conn, data, (size_t)contentLength);
Review Comment:
note there is overlap in the change with: #851
My proposal is to focus on this PR and I will update #851 after this is
merged.
the usage of mg_read should be in a while loop, according to the
[documentation])https://github.com/civetweb/civetweb/blob/master/docs/api/mg_read.md),
`mg_read` will return a negative value when there is nothing more the read.
##########
bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c:
##########
@@ -526,41 +544,59 @@ static int remoteServiceAdmin_callback(struct
mg_connection *conn) {
if (export != NULL) {
- uint64_t datalength = request_info->content_length;
- char* data = malloc(datalength + 1);
- mg_read(conn, data, datalength);
- data[datalength] = '\0';
-
- char *response = NULL;
- int responceLength = 0;
- int rc = exportRegistration_call(export, data, -1, &metadata,
&response, &responceLength);
- if (rc != CELIX_SUCCESS) {
- RSA_LOG_ERROR(rsa, "Error trying to invoke remove service, got
error %i\n", rc);
+ int64_t contentLength = request_info->content_length;
+ bool bodyRead = false;
+ char *data = NULL;
+
+ if (contentLength < 0 || (uint64_t)contentLength >
rsa->maxRequestSize) {
+ RSA_LOG_WARNING(rsa, "Rejecting request with invalid or too
large body (content length %lld, max %zu)", (long long)contentLength,
rsa->maxRequestSize);
+ mg_write(conn, request_too_large_response_headers,
strlen(request_too_large_response_headers));
Review Comment:
```suggestion
mg_send_http_error(conn, 413, "%s", "Rejecting request with
invalid or too large body (content length %lld)", (long long)contentLength);
```
I would not respond with the configured max request size.
The same setup can be use for the 500 error.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]