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

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit 644270c489d664e90071b82cfebd7124415f6785
Author: Massimo Manghi <mxman...@apache.org>
AuthorDate: Thu Apr 27 00:57:03 2023 +0200

    handling length of data in POST requests
---
 ChangeLog                       |  9 +++++++++
 src/mod_rivet_ng/TclWebapache.c |  4 ++--
 src/mod_rivet_ng/rivetCore.c    |  7 ++++---
 src/mod_rivet_ng/rivet_types.h  |  3 ++-
 src/request/apache_request.c    | 15 +++++++++++++--
 src/request/apache_request.h    |  2 +-
 6 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb27059..f0f648d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-04-11 Massimo Manghi <mxman...@apache.org>
+       * src/mod_rivet_ng/TclWebapache.c:
+       * src/mod_rivet_ng/rivetCore.c:
+       * src/mod_rivet_ng/rivet_types.h:
+       * src/request/apache_request.c:
+       * src/request/apache_request.h: handling length of data in POST 
requests. It
+       fixes ::rivet::raw_post when the POSTed data don't have variable 
sections (patch
+       provided by Scott Pitcher <sco...@svptechnicalservices.com.au>)
+
 2023-01-11 Massimo Manghi <mxman...@apache.org>
        * src/TclWeb.h: also this include file had a CONST84 specifier that 
needed to
        be converted as CONST86
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 6cb3522..44bc4db 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -1063,7 +1063,7 @@ TclWeb_GetVirtualFile(TclWebRequest *req, char 
*virtualname)
  */
 
 char *
-TclWeb_GetRawPost ( TclWebRequest *req )
+TclWeb_GetRawPost ( TclWebRequest *req, int *len )
 {
-    return ApacheRequest_get_raw_post(req->apachereq);
+    return ApacheRequest_get_raw_post(req->apachereq, len);
 }
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index c2c5266..c32ed15 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -63,7 +63,7 @@
 #define COOKIES_ARRAY_NAME "cookies"
 
 extern module rivet_module;
-extern char* TclWeb_GetRawPost (TclWebRequest *req);
+extern char* TclWeb_GetRawPost (TclWebRequest *req, int *len);
 extern mod_rivet_globals* module_globals;
 extern apr_threadkey_t*  rivet_thread_key;
 
@@ -1277,18 +1277,19 @@ TCL_CMD_HEADER( Rivet_Upload )
 TCL_CMD_HEADER ( Rivet_RawPost )
 {
     char*                   data;
+    int                     length;
     Tcl_Obj*                retval;
     rivet_thread_private*   private;
 
     THREAD_PRIVATE_DATA(private)
     CHECK_REQUEST_REC(private,"::rivet::raw_post")
 
-    data = TclWeb_GetRawPost(private->req);
+    data = TclWeb_GetRawPost(private->req, &length);
 
     if (!data) {
         data = "";
     }
-    retval = Tcl_NewStringObj(data, -1);
+    retval = Tcl_NewByteArrayObj((const unsigned char *)data, length);
     Tcl_SetObjResult(interp, retval);
     return TCL_OK;
 }
diff --git a/src/mod_rivet_ng/rivet_types.h b/src/mod_rivet_ng/rivet_types.h
index 69a9a4a..6568073 100644
--- a/src/mod_rivet_ng/rivet_types.h
+++ b/src/mod_rivet_ng/rivet_types.h
@@ -74,7 +74,8 @@ typedef struct _ApacheRequest {
     int             (*upload_hook)(void *ptr, char *buf, int len, ApacheUpload 
*upload);
     void*           hook_data;
     const char*     temp_dir;
-    char*           raw_post; /* Raw post data. */
+    char*           raw_post;           /* Raw post data. */
+    int             raw_length;
     request_rec*    r;
     int             nargs;
 } ApacheRequest;
diff --git a/src/request/apache_request.c b/src/request/apache_request.c
index 79c3f20..611e75f 100644
--- a/src/request/apache_request.c
+++ b/src/request/apache_request.c
@@ -31,7 +31,7 @@ static void req_plustospace(char *str)
 }
 
 static int
-util_read(ApacheRequest *req, const char **rbuf)
+util_read(ApacheRequest *req, const char **rbuf, int *rlen)
 {
     request_rec *r = req->r;
     int rc = OK;
@@ -55,6 +55,7 @@ util_read(ApacheRequest *req, const char **rbuf)
         }
 
         *rbuf = apr_pcalloc(r->pool, length + 1);
+       *rlen = length;
 
         while ((len_read =
                     ap_get_client_block(r, buff, sizeof(buff))) > 0) {
@@ -209,6 +210,7 @@ ApacheRequest *ApacheRequest_new(apr_pool_t *pool)
     req->hook_data      = NULL;
     req->temp_dir       = NULL;
     req->raw_post       = NULL;
+    req->raw_length     = 0;
     req->parsed         = 0;
     req->r              = NULL;
     req->nargs          = 0;
@@ -228,6 +230,7 @@ ApacheRequest *ApacheRequest_init(ApacheRequest* req, 
request_rec *r)
     req->hook_data      = NULL;
     req->temp_dir       = NULL;
     req->raw_post       = NULL;
+    req->raw_length     = 0;
     req->parsed         = 0;
     req->r              = r;
     req->nargs          = 0;
@@ -426,6 +429,7 @@ int ApacheRequest_parse_urlencoded(ApacheRequest *req)
 
     if (r->method_number == M_POST || r->method_number == M_PUT || 
r->method_number == M_DELETE) {
        const char *data = NULL;
+       int length = 0;
 
     /*
         const char *type;
@@ -437,12 +441,13 @@ int ApacheRequest_parse_urlencoded(ApacheRequest *req)
        }
     */
 
-       if ((rc = util_read(req, &data)) != OK) {
+       if ((rc = util_read(req, &data, &length)) != OK) {
            return rc;
        }
 
        if (data) {
            req->raw_post = (char*) data; /* Give people a way of getting at 
the raw data. */
+           req->raw_length = length;
            split_to_parms(req, data);
        }
     }
@@ -733,3 +738,9 @@ char *ApacheRequest_expires(ApacheRequest *req, char 
*time_str)
     return ApacheUtil_expires(req->r->pool, time_str, EXPIRES_HTTP);
 }
 
+char *ApacheRequest_get_raw_post(ApacheRequest *req, int *len)
+{
+    if (len)
+       *len = req->raw_length;
+    return req->raw_post;
+}
diff --git a/src/request/apache_request.h b/src/request/apache_request.h
index 300da12..8855961 100644
--- a/src/request/apache_request.h
+++ b/src/request/apache_request.h
@@ -102,7 +102,7 @@ ApacheUpload_info((upload), "Content-Type")
 #define ApacheRequest_set_post_max(req, max) ((req)->post_max = (max))
 #define ApacheRequest_set_temp_dir(req, dir) ((req)->temp_dir = (dir))
 
-#define ApacheRequest_get_raw_post(req) ((req)->raw_post)
+char *ApacheRequest_get_raw_post(ApacheRequest *req, int *len);
 
 char *ApacheUtil_expires(apr_pool_t *p, char *time_str, int type);
 #define EXPIRES_HTTP   1


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@tcl.apache.org
For additional commands, e-mail: commits-h...@tcl.apache.org

Reply via email to