pnoltes commented on code in PR #851:
URL: https://github.com/apache/celix/pull/851#discussion_r4579917017
##########
bundles/http_admin/http_admin/src/http_admin.c:
##########
@@ -173,6 +194,51 @@ void http_admin_removeHttpService(void *handle, void *svc
CELIX_UNUSED, const ce
}
}
+static int httpAdmin_readRequestBody(struct mg_connection* connection, long
long contentLength, size_t maxRequestBodySize, char** bufferOut, size_t*
bytesReadOut, const char** errorMsgOut) {
+ celix_autofree char* buffer = NULL;
+ size_t totalBytesRead = 0;
+ *errorMsgOut = NULL;
+ if (contentLength > 0 && (size_t)contentLength > maxRequestBodySize) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_BODY_TOO_LARGE_MSG;
+ return 413;
+ }
+ if (contentLength != 0) {
+ size_t memSize = 0;
+ celix_autoptr(FILE) stream = open_memstream(&buffer, &memSize);
+ if (stream == NULL) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_INSUFFICIENT_MEM_MSG;
+ return 500;
+ }
+
+ char chunk[CELIX_HTTP_ADMIN_READ_CHUNK_SIZE];
+ while (contentLength < 0 || totalBytesRead < (size_t)contentLength) {
+ int read = mg_read(connection, chunk, sizeof(chunk));
+ if (read == 0) {
+ break; //EOF
+ } else if (read < 0) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_READ_ERROR_MSG;
+ return 400;
+ }
+ if (totalBytesRead + (size_t)read > maxRequestBodySize) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_BODY_TOO_LARGE_MSG;
+ return 413;
+ }
+ if (fwrite(chunk, 1, (size_t)read, stream) != (size_t)read) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_INSUFFICIENT_MEM_MSG;
+ return 500;
+ }
+ totalBytesRead += (size_t)read;
+ }
+ if (contentLength > 0 && totalBytesRead < (size_t)contentLength) {
+ *errorMsgOut = CELIX_HTTP_ADMIN_INCOMPLETE_BODY_MSG;
+ return 400;
+ }
+ }
+ *bufferOut = celix_steal_ptr(buffer);
Review Comment:
The celix_autoptr in line 207, should be out of scope in line 237, and
indeed be closed. That is why i though the buffer points to the result after
fclose.
--
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]