Author: rjung
Date: Fri Aug 28 12:12:18 2015
New Revision: 1698316

URL: http://svn.apache.org/r1698316
Log:
BZ 58286: Fix crash in mod_jk and in the ISAPI
Redirector. The crash only happens on Windows
when retrieving the jk-status for the HTML format
(which is the default format). This regression
was introduced by the fix to BZ 54177.

Modified:
    tomcat/jk/trunk/native/common/jk_status.c
    tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml

Modified: tomcat/jk/trunk/native/common/jk_status.c
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_status.c?rev=1698316&r1=1698315&r2=1698316&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_status.c (original)
+++ tomcat/jk/trunk/native/common/jk_status.c Fri Aug 28 12:12:18 2015
@@ -241,9 +241,18 @@
 #define JK_STATUS_WAIT_AFTER_UPDATE        "3"
 #define JK_STATUS_REFRESH_DEF              "10"
 #define JK_STATUS_ESC_CHARS                ("<>?\"")
+
+#ifdef WIN32
+/* See also windows_strftime_preprocess() */
+#define JK_WINDOWS_TIMEZONE_PLACEHOLDER    "+????"
+#define JK_STATUS_TIME_FMT_HTML            "%Y-%m-%d %H:%M:%S " 
JK_WINDOWS_TIMEZONE_PLACEHOLDER
+#define JK_STATUS_TIME_FMT_TZ              JK_WINDOWS_TIMEZONE_PLACEHOLDER
+#else
 #define JK_STATUS_TIME_FMT_HTML            "%Y-%m-%d %H:%M:%S %z"
-#define JK_STATUS_TIME_FMT_TEXT            "%Y%m%d%H%M%S"
 #define JK_STATUS_TIME_FMT_TZ              "%z"
+#endif
+
+#define JK_STATUS_TIME_FMT_TEXT            "%Y%m%d%H%M%S"
 #define JK_STATUS_TIME_BUF_SZ              (30)
 
 #define JK_STATUS_HEAD                     "<?xml version=\"1.0\" 
encoding=\"ISO-8859-1\"?>\n" \
@@ -764,10 +773,43 @@ static char *status_strfsize(jk_uint64_t
     } while (1);
 }
 
+#ifdef WIN32
+/* Handle time formatting aspects which are not implemented by strftime
+ * on Windows.
+ * Currently only handles numeric time zone formatting
+ * which needs to be requested using JK_WINDOWS_TIMEZONE_PLACEHOLDER
+ * in the pattern.
+ */
+static const char *windows_strftime_preprocess(const char *pattern,
+                                               char *buf, size_t sz) {
+    char *found = strstr(pattern, JK_WINDOWS_TIMEZONE_PLACEHOLDER);
+    if (found != NULL && sz > strlen(pattern)) {
+        TIME_ZONE_INFORMATION tz;
+
+        strcpy(buf, pattern);
+        found = buf + (found - pattern);
+
+        if (GetTimeZoneInformation(&tz) != TIME_ZONE_ID_INVALID) {
+            tz.Bias *= -1;
+            snprintf(found, strlen(JK_WINDOWS_TIMEZONE_PLACEHOLDER), 
"%c%02d%02d",
+                     (tz.Bias >= 0 ? '+' : '-'), tz.Bias / 60, tz.Bias % 60);
+        }
+        return buf;
+    } else {
+        return pattern;
+    }
+}
+#else
+#define windows_strftime_preprocess(x, y, z) (x)
+#endif
+
 static int status_strftime(time_t clock, int mime, char *buf_time, char 
*buf_tz,
                            jk_logger_t *l)
 {
     size_t rc_time;
+#ifdef WIN32
+    char buf[JK_STATUS_TIME_BUF_SZ];
+#endif
 #ifdef _MT_CODE_PTHREAD
     struct tm res;
     struct tm *tms = localtime_r(&clock, &res);
@@ -778,11 +820,21 @@ static int status_strftime(time_t clock,
     JK_TRACE_ENTER(l);
 
     if (mime == JK_STATUS_MIME_HTML)
-        rc_time = strftime(buf_time, JK_STATUS_TIME_BUF_SZ, 
JK_STATUS_TIME_FMT_HTML, tms);
-    else {
-        rc_time = strftime(buf_time, JK_STATUS_TIME_BUF_SZ, 
JK_STATUS_TIME_FMT_TEXT, tms);
+        rc_time = strftime(buf_time, JK_STATUS_TIME_BUF_SZ,
+                           windows_strftime_preprocess(JK_STATUS_TIME_FMT_HTML,
+                                                       buf, 
JK_STATUS_TIME_BUF_SZ),
+                           tms);
+    else {
+        rc_time = strftime(buf_time, JK_STATUS_TIME_BUF_SZ,
+                           windows_strftime_preprocess(JK_STATUS_TIME_FMT_TEXT,
+                                                       buf, 
JK_STATUS_TIME_BUF_SZ),
+                           tms);
     }
-    strftime(buf_tz, JK_STATUS_TIME_BUF_SZ, JK_STATUS_TIME_FMT_TZ, tms);
+
+    strftime(buf_tz, JK_STATUS_TIME_BUF_SZ,
+             windows_strftime_preprocess(JK_STATUS_TIME_FMT_TZ,
+                                         buf, JK_STATUS_TIME_BUF_SZ),
+             tms);
 
     JK_TRACE_EXIT(l);
     return (int)rc_time;

Modified: tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml?rev=1698316&r1=1698315&r2=1698316&view=diff
==============================================================================
--- tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml Fri Aug 28 12:12:18 2015
@@ -45,6 +45,12 @@
   <subsection name="Native">
     <changelog>
       <fix>
+        <bug>58286</bug>: Fix crash in mod_jk and in the ISAPI Redirector.
+        The crash only happens on Windows when retrieving the jk-status
+        for the HTML format (which is the default format). This regression
+        was introduced by the fix to <bug>54177</bug>. (rjung)
+      </fix>
+      <fix>
         <bug>58285</bug>: Don't use GCC atomics on platforms, for which
         GCC doesn't provide an atomics implementation. This regression
         was introduced by the fix to <bug>44454</bug> and <bug>56703</bug>.



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

Reply via email to