httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cliff Woolley <jwool...@virginia.edu>
Subject [PATCH] outstanding shmcb fixes (fwd)
Date Mon, 25 Mar 2002 23:08:03 GMT

Don't know to what extent these changes affect mod_ssl for 2.0 (haven't
had time to look yet), but I figured I'd go ahead and forward them here
just in case.

--Cliff


---------- Forwarded message ----------
Date: Mon, 25 Mar 2002 23:01:35 +0000
From: Joe Orton <jorton@redhat.com>
Reply-To: modssl-users@modssl.org
To: Ralf S. Engelschall <rse@engelschall.com>
Cc: modssl-users@modssl.org
Subject: [PATCH] outstanding shmcb fixes

Here are the outstanding shmcb changes which didn't make it into 2.8.7,
extracted from Geoff's patch.  These fix the remaining SIGBUS problem(s)
on SPARC etc.

--- pkg.sslmod/ssl_scache_shmcb.c.orig	Fri Mar 30 11:00:34 2001
+++ pkg.sslmod/ssl_scache_shmcb.c	Tue Jul 10 13:37:10 2001
@@ -262,13 +262,38 @@
    memcpys can hardly make a dent on the massive memmove operations this
    cache technique avoids, nor the overheads of ASN en/decoding. */
 static unsigned int shmcb_get_safe_uint(unsigned int *);
-static void shmcb_set_safe_uint(unsigned int *, unsigned int);
+static void shmcb_set_safe_uint_ex(unsigned char *, const unsigned char *);
+#define shmcb_set_safe_uint(pdest, src) \
+	do { \
+		unsigned int tmp_uint = src; \
+		shmcb_set_safe_uint_ex((unsigned char *)pdest, \
+			(const unsigned char *)(&tmp_uint)); \
+	} while(0)
 #if 0 /* Unused so far */
 static unsigned long shmcb_get_safe_ulong(unsigned long *);
-static void shmcb_set_safe_ulong(unsigned long *, unsigned long);
+static void shmcb_set_safe_ulong_ex(unsigned char *, const unsigned char *);
+#define shmcb_set_safe_ulong(pdest, src) \
+	do { \
+		unsigned long tmp_ulong = src; \
+		shmcb_set_safe_ulong_ex((unsigned char *)pdest, \
+			(const unsigned char *)(&tmp_ulong)); \
+	} while(0)
 #endif
 static time_t shmcb_get_safe_time(time_t *);
-static void shmcb_set_safe_time(time_t *, time_t);
+static void shmcb_set_safe_time_ex(unsigned char *, const unsigned char *);
+#define shmcb_set_safe_time(pdest, src) \
+	do { \
+		time_t tmp_time = src; \
+		shmcb_set_safe_time_ex((unsigned char *)pdest, \
+			(const unsigned char *)(&tmp_time)); \
+	} while(0)
+
+/* This is necessary simply so that the size passed to memset() is not a
+ * compile-time constant, preventing the compiler from optimising it. */
+static void shmcb_safe_clear(void *ptr, size_t size)
+{
+	memset(ptr, 0, size);
+}

 /* Underlying functions for session-caching */
 static BOOL shmcb_init_memory(server_rec *, void *, unsigned int);
@@ -306,61 +331,46 @@

 static unsigned int shmcb_get_safe_uint(unsigned int *ptr)
 {
-    unsigned char *from;
     unsigned int ret;
-
-    from = (unsigned char *)ptr;
-    memcpy(&ret, from, sizeof(unsigned int));
+    shmcb_set_safe_uint_ex((unsigned char *)(&ret),
+		    (const unsigned char *)ptr);
     return ret;
 }

-static void shmcb_set_safe_uint(unsigned int *ptr, unsigned int val)
+static void shmcb_set_safe_uint_ex(unsigned char *dest,
+				const unsigned char *src)
 {
-    unsigned char *to, *from;
-
-    to = (unsigned char *)ptr;
-    from = (unsigned char *)(&val);
-    memcpy(to, from, sizeof(unsigned int));
+    memcpy(dest, src, sizeof(unsigned int));
 }

 #if 0 /* Unused so far */
 static unsigned long shmcb_get_safe_ulong(unsigned long *ptr)
 {
-    unsigned char *from;
     unsigned long ret;
-
-    from = (unsigned char *)ptr;
-    memcpy(&ret, from, sizeof(unsigned long));
+    shmcb_set_safe_ulong_ex((unsigned char *)(&ret),
+		    (const unsigned char *)ptr);
     return ret;
 }

-static void shmcb_set_safe_ulong(unsigned long *ptr, unsigned long val)
+static void shmcb_set_safe_ulong_ex(unsigned char *dest,
+				const unsigned char *src)
 {
-    unsigned char *to, *from;
-
-    to = (unsigned char *)ptr;
-    from = (unsigned char *)(&val);
-    memcpy(to, from, sizeof(unsigned long));
+    memcpy(dest, src, sizeof(unsigned long));
 }
 #endif

 static time_t shmcb_get_safe_time(time_t * ptr)
 {
-    unsigned char *from;
     time_t ret;
-
-    from = (unsigned char *)ptr;
-    memcpy(&ret, from, sizeof(time_t));
+    shmcb_set_safe_time_ex((unsigned char *)(&ret),
+		    (const unsigned char *)ptr);
     return ret;
 }

-static void shmcb_set_safe_time(time_t * ptr, time_t val)
+static void shmcb_set_safe_time_ex(unsigned char *dest,
+				const unsigned char *src)
 {
-    unsigned char *to, *from;
-
-    to = (unsigned char *)ptr;
-    from = (unsigned char *)(&val);
-    memcpy(to, from, sizeof(time_t));
+    memcpy(dest, src, sizeof(time_t));
 }

 /*
@@ -1176,7 +1186,7 @@
                 "internal error");
         return FALSE;
     }
-    memset(idx, 0, sizeof(SHMCBIndex));
+    shmcb_safe_clear(idx, sizeof(SHMCBIndex));
     shmcb_set_safe_time(&(idx->expires), expiry_time);
     shmcb_set_safe_uint(&(idx->offset), new_offset);

______________________________________________________________________
Apache Interface to OpenSSL (mod_ssl)                   www.modssl.org
User Support Mailing List                      modssl-users@modssl.org
Automated List Manager                            majordomo@modssl.org


Mime
View raw message