You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-commits@axis.apache.org by ro...@apache.org on 2026/04/18 01:41:44 UTC

(axis-axis2-c-core) branch master updated (a713417c4 -> d83455a5c)

This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git


    from a713417c4 Address Gemini pro round 2: trailing whitespace trim, const correctness
     new f4b9108a0 Fix JSON processor to preserve query string from HTTP request
     new d83455a5c Fix sprintf → snprintf in JSON error response, TODO on read loop bug

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/financial_benchmark_service_handler.c      | 10 ++++++++-
 .../axis2_apache2_request_processor_json_impl.c    | 26 ++++++++++++++++++----
 2 files changed, 31 insertions(+), 5 deletions(-)


(axis-axis2-c-core) 02/02: Fix sprintf → snprintf in JSON error response, TODO on read loop bug

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git

commit d83455a5cf2ed6dc57d79abadcb72dfd0d33b9d2
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Fri Apr 17 15:40:39 2026 -1000

    Fix sprintf → snprintf in JSON error response, TODO on read loop bug
    
    sprintf → snprintf: the JSON error response formatter used sprintf
    without bounds checking. Changed to snprintf(json_response, buffer_size, ...)
    matching the safer pattern used in axis2_json_secure_fault.c.
    
    TODO added to the request body read loop documenting a pre-existing
    integer underflow bug (size_t wraps to SIZE_MAX when buffer is exactly
    full). The fix requires restructuring the while(1) loop to grow the
    buffer BEFORE reading, which touches a critical code path shared by
    all JSON services. Deferred to a dedicated commit with its own testing.
    
    Both findings from gemini-2.5-pro review of the query string fix commit.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <no...@anthropic.com>
---
 .../apache2/axis2_apache2_request_processor_json_impl.c  | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c b/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
index b0abd484f..4bf33f258 100644
--- a/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
+++ b/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
@@ -915,7 +915,7 @@ axis2_apache2_json_processor_write_json_error_response(
     json_response = AXIS2_MALLOC(env->allocator, buffer_size);
     if (json_response)
     {
-        sprintf(json_response,
+        snprintf(json_response, buffer_size,
             "{\n"
             "  \"error\": {\n"
             "    \"code\": %d,\n"
@@ -1009,7 +1009,19 @@ axis2_apache2_json_processor_parse_and_process_json(
                 env, out_stream, "Memory allocation error", 500);
         }
 
-        /* Read in chunks, growing buffer as needed */
+        /* Read in chunks, growing buffer as needed.
+         *
+         * TODO (Gemini pro review, April 2026): This loop has a potential
+         * integer underflow when the buffer is exactly full. The expression
+         *   read_space = current_size - total_read - 1;
+         * underflows size_t to SIZE_MAX when total_read == current_size,
+         * which is then cast to (int)-1 and passed to axutil_stream_read.
+         * The buffer growth logic should be moved BEFORE the read call
+         * (not after) so the buffer is always large enough before reading.
+         * This is a pre-existing bug unrelated to the ?fields= feature;
+         * fixing it requires restructuring the loop and dedicated testing
+         * since this code path handles every JSON request to every service.
+         */
         while (1)
         {
             /* SECURITY: Validate buffer space before read to prevent underflow */


(axis-axis2-c-core) 01/02: Fix JSON processor to preserve query string from HTTP request

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-c-core.git

commit f4b9108a0ec04c8e6cd52128be5f37aad18f7b97
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Fri Apr 17 15:32:53 2026 -1000

    Fix JSON processor to preserve query string from HTTP request
    
    The JSON request processor in axis2_apache2_request_processor_json_impl.c
    used request->uri (path only, no query string) while the SOAP worker in
    apache2_worker.c has always used request->unparsed_uri (path + query).
    This inconsistency meant ?fields= and any other query parameters were
    silently stripped before reaching JSON service handlers.
    
    Changed two references from request->uri to request->unparsed_uri:
      - Line 513: service_path for logging and routing
      - Line 661: request_uri passed to transport_utils → msg_ctx endpoint ref
    
    When no query string is present, unparsed_uri == uri — zero behavior
    change for existing services. Verified: Kanaha CameraControlService and
    all other JSON services use POST with JSON body and no query parameters.
    
    This unblocks ?fields= response field filtering in the financial
    benchmark service and any future query-parameter-based features.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <no...@anthropic.com>
---
 .../src/financial_benchmark_service_handler.c                  | 10 +++++++++-
 .../server/apache2/axis2_apache2_request_processor_json_impl.c | 10 ++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/samples/user_guide/financial-benchmark-service/src/financial_benchmark_service_handler.c b/samples/user_guide/financial-benchmark-service/src/financial_benchmark_service_handler.c
index 2810809e1..98c2292a9 100644
--- a/samples/user_guide/financial-benchmark-service/src/financial_benchmark_service_handler.c
+++ b/samples/user_guide/financial-benchmark-service/src/financial_benchmark_service_handler.c
@@ -335,8 +335,16 @@ financial_benchmark_service_invoke_json(
         axis2_endpoint_ref_t *to_ref = axis2_msg_ctx_get_to(msg_ctx, env);
         if (to_ref)
             uri = axis2_endpoint_ref_get_address(to_ref, env);
-        if (uri)
+        if (uri) {
+            AXIS2_LOG_INFO(env->log,
+                "FinancialBenchmarkService: endpoint ref address for fields extraction: '%s'",
+                uri);
             fields_csv = finbench_extract_fields_param(env, uri);
+            if (fields_csv) {
+                AXIS2_LOG_INFO(env->log,
+                    "FinancialBenchmarkService: extracted fields_csv: '%s'", fields_csv);
+            }
+        }
     }
 
     /* If we couldn't get operation from context, try parsing from JSON */
diff --git a/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c b/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
index 293097f72..b0abd484f 100644
--- a/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
+++ b/src/core/transport/http/server/apache2/axis2_apache2_request_processor_json_impl.c
@@ -510,7 +510,13 @@ axis2_apache2_json_processor_process_request_body_impl(
         content_type = "application/json";  /* Default for HTTP/2 JSON */
     }
 
-    service_path = request->uri;  /* Service path from request URI */
+    /* Use unparsed_uri (includes query string) not uri (path only).
+     * This matches apache2_worker.c line 257 which has always used
+     * request->unparsed_uri for the SOAP/XML path. The JSON processor
+     * using request->uri was an oversight that stripped query parameters
+     * like ?fields= before they reached the service handler.
+     * When no query string is present, unparsed_uri == uri. */
+    service_path = request->unparsed_uri;
 
     AXIS2_LOG_INFO(env->log,
         "[JSON_PROCESSOR_TRACE] Got Content-Type: %s, Service: %s",
@@ -658,7 +664,7 @@ axis2_apache2_json_processor_process_request_body_impl(
                                 engine_content_type,
                                 engine_content_length,
                                 NULL,  /* soap_action_header - not needed for JSON */
-                                request->uri);
+                                request->unparsed_uri);  /* preserve query string */
 
     AXIS2_LOG_INFO(env->log,
         "[JSON_PROCESSOR_ENGINE] Engine processing completed with status: %d", engine_status);