You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2017/10/21 10:18:00 UTC

svn commit: r1812814 - in /tcl/rivet/branches/2.3: ChangeLog rivet/init.tcl.in rivet/rivet-tcl/redirect.tcl src/librivet/rivetWWW.c

Author: mxmanghi
Date: Sat Oct 21 10:18:00 2017
New Revision: 1812814

URL: http://svn.apache.org/viewvc?rev=1812814&view=rev
Log:
    * rivet/init.tcl.in: Following Jeff Lawson's suggestion we check
    if init.tcl is loaded from within mod_rivet. If we're not running
    from it we don't divert the [exit] command 
    * tcl/rivet-tcl/redirect.tcl: now handling generic boolean arguments
    or any integer > 0 (as for the HTTP status codes)
    * src/librivet/rivetWWW.c: fixed subtle buffer overflow
    with sprintfn


Modified:
    tcl/rivet/branches/2.3/ChangeLog
    tcl/rivet/branches/2.3/rivet/init.tcl.in
    tcl/rivet/branches/2.3/rivet/rivet-tcl/redirect.tcl
    tcl/rivet/branches/2.3/src/librivet/rivetWWW.c

Modified: tcl/rivet/branches/2.3/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/2.3/ChangeLog?rev=1812814&r1=1812813&r2=1812814&view=diff
==============================================================================
--- tcl/rivet/branches/2.3/ChangeLog (original)
+++ tcl/rivet/branches/2.3/ChangeLog Sat Oct 21 10:18:00 2017
@@ -1,3 +1,12 @@
+2017-10-13 Massimo Manghi <mx...@apache.org>
+    * rivet/init.tcl.in: Following Jeff Lawson's suggestion we check
+    if init.tcl is loaded from within mod_rivet. If we're not running
+    from it we don't divert the [exit] command 
+    * tcl/rivet-tcl/redirect.tcl: now handling generic boolean arguments
+    or any integer > 0 (as for the HTTP status codes)
+    * src/librivet/rivetWWW.c: fixed subtle buffer overflow
+    with sprintfn
+
 2017-08-08 Massimo Manghi <mx...@apache.org>
     * src/apache-2/mod_rivet.c: implementing check on post_config
     hook calling Rivet_InitHandler. This avoids the module

Modified: tcl/rivet/branches/2.3/rivet/init.tcl.in
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/2.3/rivet/init.tcl.in?rev=1812814&r1=1812813&r2=1812814&view=diff
==============================================================================
--- tcl/rivet/branches/2.3/rivet/init.tcl.in (original)
+++ tcl/rivet/branches/2.3/rivet/init.tcl.in Sat Oct 21 10:18:00 2017
@@ -170,15 +170,21 @@ namespace eval ::Rivet {
 
 } ;## namespace eval ::Rivet
 
-## eventually we have to divert Tcl ::exit to ::rivet::exit
+## if we are running from within mod_rivet we have already
+## defined ::rivet::exit (mod_rivet.c: Rivet_PerInterpInit)
+## and we divert Tcl ::exit to ::rivet::exit
 
-rename ::exit ::Rivet::tclcore_exit
-proc ::exit {code} {
+if {[info commands ::rivet::exit] != ""} {
+
+    rename ::exit ::Rivet::tclcore_exit
+    proc ::exit {code} {
+
+        if {[string is integer $code]} {
+            eval ::rivet::exit $code
+        } else {
+            eval ::rivet::exit 0
+        }
 
-    if {[string is integer $code]} {
-        eval ::rivet::exit $code
-    } else {
-        eval ::rivet::exit 0
     }
 
 }

Modified: tcl/rivet/branches/2.3/rivet/rivet-tcl/redirect.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/2.3/rivet/rivet-tcl/redirect.tcl?rev=1812814&r1=1812813&r2=1812814&view=diff
==============================================================================
--- tcl/rivet/branches/2.3/rivet/rivet-tcl/redirect.tcl (original)
+++ tcl/rivet/branches/2.3/rivet/rivet-tcl/redirect.tcl Sat Oct 21 10:18:00 2017
@@ -8,7 +8,11 @@
 #
 #   - url               - URL to which we are redirecting the client
 #   - permanent:[0 | 1] - whether redirection will be permanent (default)
+#     or
+#   - permanent: code   - returns any HTTP integer code. In this context
+#                         only the 3xx status codes are meaningful
 #
+#   $ Id: $
 #
 
 namespace eval ::rivet {
@@ -20,11 +24,37 @@ namespace eval ::rivet {
             return  -code error \
                     -errorcode headers_already_sent \
                     -errorinfo "Impossible to redirect: headers already sent"
+
+        }
+
+        # In order to preserve compatibility 
+        # with the past we chec whether we are
+        # dealing with a boolean argument and handle
+        # it accordingly 
+
+        if {[string is boolean $permanent] } {
+
+            if {[string is true $permanent]} {
+                set http_code 301
+            } else {
+                set http_code 302
+            } 
+
+        } elseif {[string is integer $permanent] && ($permanent > 0)} {
+
+            set http_code $permanent
+
+        } else {
+
+            return  -code error \
+                    -errorcode invalid_http_code \
+                    -errorinfo "Invalid HTTP status code: $permanent"
+
         }
 
         ::rivet::no_body ; ## don’t output anything on a redirect
         ::rivet::headers set Location $url
-        ::rivet::headers numeric [expr {$permanent ? "301" : "302"}]
+        ::rivet::headers numeric $http_code
         ::rivet::abort_page [dict create error_code redirect location $url] ; ## stop any further processing
 
         return -error ok 

Modified: tcl/rivet/branches/2.3/src/librivet/rivetWWW.c
URL: http://svn.apache.org/viewvc/tcl/rivet/branches/2.3/src/librivet/rivetWWW.c?rev=1812814&r1=1812813&r2=1812814&view=diff
==============================================================================
--- tcl/rivet/branches/2.3/src/librivet/rivetWWW.c (original)
+++ tcl/rivet/branches/2.3/src/librivet/rivetWWW.c Sat Oct 21 10:18:00 2017
@@ -109,8 +109,8 @@ TCL_CMD_HEADER( Rivet_UnescapeStringCmd
             digit2 = Rivet_HexToDigit(c2 = *++origStringP);
 
             if (digit1 == -1 || digit2 == -1) {
-                char buf[2];
-                snprintf( buf, 2, "%c%c", c, c2 );
+                char buf[3];
+                snprintf (buf,3,"%c%c",c,c2);
                 Tcl_AppendResult( interp,
                     Tcl_GetStringFromObj( objv[0], NULL ),
                     ": bad char in hex sequence %", buf, (char *)NULL );



---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org