r3171 - trunk/varnish-cache/lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Mon Sep 8 16:30:31 CEST 2008


Author: phk
Date: 2008-09-08 16:30:31 +0200 (Mon, 08 Sep 2008)
New Revision: 3171

Modified:
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
Log:
On platforms with multibyte sa_family and big endian, the compiled
ACLs would not work, as evidenced by #311.

Add a log message for unknown sa_families, and use memmove to extract
the sa_family member of the sockaddr into a suitably sized variable.

Diagnosed by:	Mithrandir
Fixes:	#311


Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2008-09-08 14:22:42 UTC (rev 3170)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2008-09-08 14:30:31 UTC (rev 3171)
@@ -328,23 +328,37 @@
 	int depth, l, m, i;
 	unsigned at[VRT_ACL_MAXADDR + 1];
 	const char *oc;
+	struct sockaddr sa;
 
 	Fh(tl, 0, "\nstatic int\n");
 	Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n",
 	    pfx, acln);
 	Fh(tl, 0, "{\n");
-	Fh(tl, 0, "\tunsigned fam;\n");
 	Fh(tl, 0, "\tconst unsigned char *a;\n");
+	assert(sizeof (unsigned char) == 1);
+	assert(sizeof (unsigned short) == 2);
+	assert(sizeof (unsigned int) == 4);
+	if (sizeof sa.sa_family == 1)
+		Fh(tl, 0, "\tunsigned char fam;\n");
+	else if (sizeof sa.sa_family == 2)
+		Fh(tl, 0, "\tunsigned short fam;\n");
+	else if (sizeof sa.sa_family == 4)
+		Fh(tl, 0, "\tunsigned int fam;\n");
+	else
+		assert(0 == __LINE__);
+		
 	Fh(tl, 0, "\n");
 	Fh(tl, 0, "\ta = p;\n");
-	Fh(tl, 0, "\tfam = a[%d];\n", offsetof(struct sockaddr, sa_family));
+	Fh(tl, 0, "\tVRT_memmove(&fam, a + %d, sizeof fam);\n",
+	    offsetof(struct sockaddr, sa_family));
 	Fh(tl, 0, "\tif (fam == %d)\n", PF_INET);
 	Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in, sin_addr));
 	Fh(tl, 0, "\telse if (fam == %d)\n", PF_INET6);
 	Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in6, sin6_addr));
-	Fh(tl, 0, "\telse\n");
+	Fh(tl, 0, "\telse {\n");
+	Fh(tl, 0, "\t\tVRT_acl_log(sp, \"NO_FAM %s\");\n", acln);
 	Fh(tl, 0, "\t\treturn(0);\n");
-	Fh(tl, 0, "\n");
+	Fh(tl, 0, "\t}\n\n");
 	depth = -1;
 	oc = 0;
 	at[0] = 256;




More information about the varnish-commit mailing list