[libxslt] Remove norm:localTime extension function



commit b9d63e5f53c29be83f72849e4ac93bb42f737b9b
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Fri Feb 3 12:34:14 2017 +0100

    Remove norm:localTime extension function
    
    The length of the input string wasn't checked, resulting in a
    minor information leak. This extension function was non-standard
    and undocumented and used a custom date format, so it seems best
    to remove it.
    
    Note that with the fix to bug #758192, it's possible to convert
    between time zones using date:add and date:difference:
    
        date:add($tz, date:difference($tz, $date-time))
    
    $tz is an arbitrary dateTime in the target time zone. If you
    want to convert to the local time zone, set $tz to the current
    dateTime returned by date:date-time().
    
    Originally reported to Chromium:
    
    https://crbug.com/670720

 config.h.in     |    6 ---
 configure.in    |    2 +-
 libxslt/extra.c |  136 -------------------------------------------------------
 libxslt/extra.h |    8 ---
 4 files changed, 1 insertions(+), 151 deletions(-)
---
diff --git a/config.h.in b/config.h.in
index 8f7d8c0..682eadc 100644
--- a/config.h.in
+++ b/config.h.in
@@ -3,9 +3,6 @@
 /* Define to 1 if you have the <ansidecl.h> header file. */
 #undef HAVE_ANSIDECL_H
 
-/* Define to 1 if you have the `asctime' function. */
-#undef HAVE_ASCTIME
-
 /* Define to 1 if you have the `clock_gettime' function. */
 #undef HAVE_CLOCK_GETTIME
 
@@ -69,9 +66,6 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
-/* Define to 1 if you have the `mktime' function. */
-#undef HAVE_MKTIME
-
 /* Define to 1 if you have the <nan.h> header file. */
 #undef HAVE_NAN_H
 
diff --git a/configure.in b/configure.in
index 8bdf45a..019f022 100644
--- a/configure.in
+++ b/configure.in
@@ -248,7 +248,7 @@ AC_CHECK_FUNC(fabs, , AC_CHECK_LIB(m, fabs,
 
 
 AC_CHECK_FUNCS(gettimeofday)
-AC_CHECK_FUNCS(mktime localtime localtime_r asctime time gmtime gmtime_r ftime)
+AC_CHECK_FUNCS(localtime localtime_r time gmtime gmtime_r ftime)
 
 dnl Checking the standard string functions availability
 AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,
diff --git a/libxslt/extra.c b/libxslt/extra.c
index 17df4ba..2c99e4c 100644
--- a/libxslt/extra.c
+++ b/libxslt/extra.c
@@ -14,9 +14,6 @@
 #include "libxslt.h"
 
 #include <string.h>
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
@@ -148,134 +145,6 @@ xsltFunctionNodeSet(xmlXPathParserContextPtr ctxt, int nargs){
     }
 }
 
-
-/*
- * Okay the following really seems unportable and since it's not
- * part of any standard I'm not too ashamed to do this
- */
-#if defined(linux) || defined(__sun)
-#if defined(HAVE_MKTIME) && defined(HAVE_LOCALTIME) && defined(HAVE_ASCTIME)
-#define WITH_LOCALTIME
-
-/**
- * xsltFunctionLocalTime:
- * @ctxt:  the XPath Parser context
- * @nargs:  the number of arguments
- *
- * Implement the localTime XSLT function used by NORM
- *   string localTime(???)
- *
- * This function is available in Norm's extension namespace
- * Code (and comments) contributed by Norm
- */
-static void
-xsltFunctionLocalTime(xmlXPathParserContextPtr ctxt, int nargs) {
-    xmlXPathObjectPtr obj;
-    char *str;
-    char digits[5];
-    char result[29];
-    long int field;
-    time_t gmt, lmt;
-    struct tm gmt_tm;
-    struct tm *local_tm;
-
-    if (nargs != 1) {
-       xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
-                      "localTime() : invalid number of args %d\n", nargs);
-       ctxt->error = XPATH_INVALID_ARITY;
-       return;
-    }
-
-    obj = valuePop(ctxt);
-
-    if (obj->type != XPATH_STRING) {
-       obj = xmlXPathConvertString(obj);
-    }
-    if (obj == NULL) {
-       valuePush(ctxt, xmlXPathNewString((const xmlChar *)""));
-       return;
-    }
-
-    str = (char *) obj->stringval;
-
-    /* str = "$Date$" */
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+7, 4);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_year = field - 1900;
-
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+12, 2);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_mon = field - 1;
-
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+15, 2);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_mday = field;
-
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+18, 2);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_hour = field;
-
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+21, 2);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_min = field;
-
-    memset(digits, 0, sizeof(digits));
-    strncpy(digits, str+24, 2);
-    field = strtol(digits, NULL, 10);
-    gmt_tm.tm_sec = field;
-
-    /* Now turn gmt_tm into a time. */
-    gmt = mktime(&gmt_tm);
-
-
-    /*
-     * FIXME: it's been too long since I did manual memory management.
-     * (I swore never to do it again.) Does this introduce a memory leak?
-     */
-    local_tm = localtime(&gmt);
-
-    /*
-     * Calling localtime() has the side-effect of setting timezone.
-     * After we know the timezone, we can adjust for it
-     */
-#if !defined(__FreeBSD__)
-    lmt = gmt - timezone;
-#else  /* FreeBSD DOESN'T have such side-ffect */
-    lmt = gmt - local_tm->tm_gmtoff;
-#endif
-    /*
-     * FIXME: it's been too long since I did manual memory management.
-     * (I swore never to do it again.) Does this introduce a memory leak?
-     */
-    local_tm = localtime(&lmt);
-
-    /*
-     * Now convert local_tm back into a string. This doesn't introduce
-     * a memory leak, so says asctime(3).
-     */
-
-    str = asctime(local_tm);           /* "Tue Jun 26 05:02:16 2001" */
-                                       /*  0123456789 123456789 123 */
-
-    memset(result, 0, sizeof(result)); /* "Thu, 26 Jun 2001" */
-                                       /*  0123456789 12345 */
-
-    strncpy(result, str, 20);
-    strcpy(result+20, "???");          /* tzname doesn't work, fake it */
-    strncpy(result+23, str+19, 5);
-
-    /* Ok, now result contains the string I want to send back. */
-    valuePush(ctxt, xmlXPathNewString((xmlChar *)result));
-}
-#endif
-#endif /* linux or sun */
-
-
 /**
  * xsltRegisterExtras:
  * @ctxt:  a XSLT process context
@@ -304,11 +173,6 @@ xsltRegisterAllExtras (void) {
     xsltRegisterExtModuleFunction((const xmlChar *) "node-set",
                                  XSLT_XT_NAMESPACE,
                                  xsltFunctionNodeSet);
-#ifdef WITH_LOCALTIME
-    xsltRegisterExtModuleFunction((const xmlChar *) "localTime",
-                                 XSLT_NORM_SAXON_NAMESPACE,
-                                 xsltFunctionLocalTime);
-#endif
     xsltRegisterExtModuleElement((const xmlChar *) "debug",
                                 XSLT_LIBXSLT_NAMESPACE,
                                 NULL,
diff --git a/libxslt/extra.h b/libxslt/extra.h
index 6929e3c..1b36d56 100644
--- a/libxslt/extra.h
+++ b/libxslt/extra.h
@@ -48,14 +48,6 @@ extern "C" {
 #define XSLT_XALAN_NAMESPACE ((xmlChar *)      \
                                "org.apache.xalan.xslt.extensions.Redirect")
 
-/**
- * XSLT_NORM_SAXON_NAMESPACE:
- *
- * This is Norm's namespace for SAXON extensions.
- */
-#define XSLT_NORM_SAXON_NAMESPACE ((xmlChar *) \
-       "http://nwalsh.com/xslt/ext/com.nwalsh.saxon.CVS";)
-
 
 XSLTPUBFUN void XSLTCALL
                xsltFunctionNodeSet     (xmlXPathParserContextPtr ctxt,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]