Oipo commented on a change in pull request #315:
URL: https://github.com/apache/celix/pull/315#discussion_r565956202



##########
File path: 
bundles/remote_services/remote_service_admin_dfi/gtest/src/tst_activator.c
##########
@@ -135,12 +135,30 @@ static bool bndTestRemoteString(void *handle) {
     pthread_mutex_lock(&act->mutex);
     if (act->remoteExample != NULL) {
         //test string Call with taking ownership
-        char *tmp = strndup("test1", 1024);
+
+        //test with a large very large string to verify mg_write limits.
+        int testLength = 1024 * 1024 * 5; //5mb
+        char *buf = NULL;
+        size_t bufLen = 0;
+        FILE* stream = open_memstream(&buf, &bufLen);
+        for (int i =0; i < testLength; i++) {
+            fputc('A', stream);
+        }
+        fputc('\0', stream);
+        fclose(stream);
         char *result = NULL;
-        TIMED_EXPR(act->remoteExample->setName1(act->remoteExample->handle, 
tmp, &result));
+        TIMED_EXPR(act->remoteExample->setName1(act->remoteExample->handle, 
buf, &result));
         printf("Call setName1 took %f ms\n", diff);
         //note setName1 should take ownership of tmp, so no free(tmp) needed.
-        ok = strncmp("test1", result, 1024) == 0;
+        ok = strncmp("AAAA", result, 4) == 0;

Review comment:
       This doesn´t check if result has more than 4 characters anymore.

##########
File path: 
bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
##########
@@ -505,7 +507,24 @@ static int remoteServiceAdmin_callback(struct 
mg_connection *conn) {
 
             if (rc == CELIX_SUCCESS && response != NULL) {
                 mg_write(conn, data_response_headers, 
strlen(data_response_headers));
-                mg_write(conn, response, strlen(response));
+
+                char *bufLoc = response;
+                size_t bytesLeft = strlen(response);
+                if (bytesLeft > INT_MAX) {
+                    //NOTE arcording to civetweb mg_write, there is a limit on 
mg_write for INT_MAX.
+                    RSA_LOG_WARNING(rsa, "nr of bytes to send for a remote 
call is > INT_MAX, this can lead to issues\n");
+                }
+                while (bytesLeft > 0) {
+                    int send = mg_write(conn, response, strlen(response));

Review comment:
       This sends the same part of the response (from beginning till `send`) 
continuously. You probably meant `int send = mg_write(conn, response + bufLoc, 
bytesLeft-bufLoc)`.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to