generate_certificate_valid_date(): Fall back to using gmtime() if gmtime_r() isn...
authorFabian Keil <fk@fabiankeil.de>
Sun, 7 Jun 2020 14:56:05 +0000 (16:56 +0200)
committerFabian Keil <fk@fabiankeil.de>
Mon, 8 Jun 2020 13:34:36 +0000 (15:34 +0200)
As Lee reported it's not available on Windows.

ssl.c

diff --git a/ssl.c b/ssl.c
index 852a9ce..acd9f90 100644 (file)
--- a/ssl.c
+++ b/ssl.c
@@ -1336,18 +1336,33 @@ static int ssl_certificate_is_invalid(const char *cert_file)
 static int generate_certificate_valid_date(time_t time_spec, char *buffer,
                                            size_t buffer_size)
 {
 static int generate_certificate_valid_date(time_t time_spec, char *buffer,
                                            size_t buffer_size)
 {
+#ifdef HAVE_GMTIME_R
    struct tm valid_date;
    struct tm valid_date;
+#endif
+   struct tm *timeptr;
    size_t ret;
 
    size_t ret;
 
-#ifndef HAVE_GMTIME_R
-#error HTTP inspection currently requires gmtime_r() which seems to be missing
+#ifdef HAVE_GMTIME_R
+   timeptr = gmtime_r(&time_spec, &valid_date);
+#elif defined(MUTEX_LOCKS_AVAILABLE)
+   privoxy_mutex_lock(&gmtime_mutex);
+   timeptr = gmtime(&time_spec);
+#else
+#warning Using unlocked gmtime()
+   timeptr = gmtime(&time_spec);
 #endif
 #endif
-   if (NULL == gmtime_r(&time_spec, &valid_date))
+   if (NULL == timeptr)
    {
    {
+#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE)
+      privoxy_mutex_unlock(&gmtime_mutex);
+#endif
       return 1;
    }
 
       return 1;
    }
 
-   ret = strftime(buffer, buffer_size, "%Y%m%d%H%M%S", &valid_date);
+   ret = strftime(buffer, buffer_size, "%Y%m%d%H%M%S", timeptr);
+#if !defined(HAVE_GMTIME_R) && defined(MUTEX_LOCKS_AVAILABLE)
+   privoxy_mutex_unlock(&gmtime_mutex);
+#endif
    if (ret != 14)
    {
       return 1;
    if (ret != 14)
    {
       return 1;