pnoltes commented on code in PR #851:
URL: https://github.com/apache/celix/pull/851#discussion_r4503614874


##########
bundles/http_admin/http_admin/src/http_admin.c:
##########
@@ -173,6 +183,39 @@ void http_admin_removeHttpService(void *handle, void *svc 
CELIX_UNUSED, const ce
     }
 }
 
+static int httpAdmin_readRequestBody(struct mg_connection* connection, long 
long contentLength, char** bufferOut, size_t* bytesReadOut, const char** 
errorMsgOut) {
+    celix_autofree char* buffer = NULL;
+    size_t totalBytesRead = 0;
+    *errorMsgOut = NULL;
+    if (contentLength > 0) {
+        size_t length = (contentLength > INT_MAX) ? INT_MAX : 
(size_t)contentLength;
+        buffer = malloc(length + 1);
+        if (buffer == NULL) {
+            *errorMsgOut = CELIX_HTTP_ADMIN_INSUFFICIENT_MEM_MSG;
+            return 500;
+        }
+
+        while (totalBytesRead < length) {
+            int read = mg_read(connection, buffer + totalBytesRead, length - 
totalBytesRead);
+            if (read == 0) {
+                break; //EOF
+            } else if (read < 0) {
+                *errorMsgOut = CELIX_HTTP_ADMIN_READ_ERROR_MSG;
+                return 400;
+            }
+            totalBytesRead += (size_t)read;
+        }
+        if (totalBytesRead < length) {

Review Comment:
   yeah sorry, good point. Added handling of `contentLength == -1` and simplied 
the impl using memstream



##########
bundles/http_admin/http_admin/src/http_admin.c:
##########
@@ -173,6 +183,39 @@ void http_admin_removeHttpService(void *handle, void *svc 
CELIX_UNUSED, const ce
     }
 }
 
+static int httpAdmin_readRequestBody(struct mg_connection* connection, long 
long contentLength, char** bufferOut, size_t* bytesReadOut, const char** 
errorMsgOut) {
+    celix_autofree char* buffer = NULL;
+    size_t totalBytesRead = 0;
+    *errorMsgOut = NULL;
+    if (contentLength > 0) {
+        size_t length = (contentLength > INT_MAX) ? INT_MAX : 
(size_t)contentLength;
+        buffer = malloc(length + 1);

Review Comment:
   agree, done



-- 
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]

Reply via email to