git: e3fb16b88ac9 - main - www/spawn-fcgi: unbreaks usage of unix sockets

From: Rodrigo Osorio <rodrigo_at_FreeBSD.org>
Date: Mon, 02 Nov 2026 19:40:01 UTC
The branch main has been updated by rodrigo:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e3fb16b88ac9c7ce918325d54d44ece3e572ff39

commit e3fb16b88ac9c7ce918325d54d44ece3e572ff39
Author:     Rodrigo Osorio <rodrigo@FreeBSD.org>
AuthorDate: 2026-11-02 19:31:39 +0000
Commit:     Rodrigo Osorio <rodrigo@FreeBSD.org>
CommitDate: 2026-11-02 19:37:33 +0000

    www/spawn-fcgi: unbreaks usage of unix sockets
    
    Add a patch to fix Unix socket usage on FreeBSD,
    based on the analysis provided by Philip.
    
    PR:             300386
    Reported by:    Philipp Wuensche <cryx-ports@h3q.com>
---
 www/spawn-fcgi/Makefile                      |  3 ++
 www/spawn-fcgi/files/patch-src__spawn-fcgi.c | 54 ++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/www/spawn-fcgi/Makefile b/www/spawn-fcgi/Makefile
index 0f12b1e6ec0a..3975295d2112 100644
--- a/www/spawn-fcgi/Makefile
+++ b/www/spawn-fcgi/Makefile
@@ -1,8 +1,11 @@
 PORTNAME=	spawn-fcgi
 PORTVERSION=	1.6.6
+PORTREVISION=	1
 CATEGORIES=	www
 MASTER_SITES=	http://download.lighttpd.net/spawn-fcgi/releases-1.6.x/
 
+PATCH_STRIP=	-p1
+
 MAINTAINER=	ports@FreeBSD.org
 COMMENT=	Spawns fastcgi applications
 WWW=		https://redmine.lighttpd.net/projects/spawn-fcgi
diff --git a/www/spawn-fcgi/files/patch-src__spawn-fcgi.c b/www/spawn-fcgi/files/patch-src__spawn-fcgi.c
new file mode 100644
index 000000000000..73a821359dae
--- /dev/null
+++ b/www/spawn-fcgi/files/patch-src__spawn-fcgi.c
@@ -0,0 +1,54 @@
+From 875e0bd21eb926590ce1ff29ddd4d3c510d8662d Mon Sep 17 00:00:00 2001
+From: Rodrigo Osorio <rodrigo@osorio.me>
+Date: Sun, 1 Nov 2026 16:16:48 +0100
+Subject: [PATCH] Don't rely on SUN_LEN to calculate sockaddr_un size
+
+"Advanced Programming in the UNIX Environmen suggestion" (chapter 17.3):
+The way we determine the size of the address to bind is to calculate
+the offset of the sun_path member in the sockaddr_un structure and
+add to it the length of the  to it the length of the pathname, not
+including the terminating null byte.
+
+Since implementations vary in which members precede sun_path in the
+sockaddr_un structure, we use the offsetof macro from <stddef.h>
+(included by apue.h) to calculate the offset of the sun_path member
+from the start of the structure.
+
+This is a rework of the suggested fix done by Philipp Wuensche
+<cryx-ports@h3q.com> in  https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300386
+---
+ src/spawn-fcgi.c | 11 +++++------
+ 1 file changed, 5 insertions(+), 6 deletions(-)
+
+diff --git a/src/spawn-fcgi.c b/src/spawn-fcgi.c
+index 436a515..3af99ea 100644
+--- a/src/spawn-fcgi.c
++++ b/src/spawn-fcgi.c
+@@ -8,6 +8,7 @@
+ #include <sys/time.h>
+ #include <sys/stat.h>
+ 
++#include <stddef.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <errno.h>
+@@ -94,12 +95,10 @@ static int bind_socket(const char *addr, unsigned short port, const char *unixso
+ 		if (strlen(unixsocket) > sizeof(fcgi_addr_un.sun_path) - 1) return -1;
+ 		strcpy(fcgi_addr_un.sun_path, unixsocket);
+ 
+-#ifdef SUN_LEN
+-		servlen = SUN_LEN(&fcgi_addr_un);
+-#else
+-		/* stevens says: */
+-		servlen = strlen(fcgi_addr_un.sun_path) + sizeof(fcgi_addr_un.sun_family);
+-#endif
++		/* don't rely on SUN_LEN (hidden on BSD with _XOPEN_SOURCE) or on
++		 * sun_path following sun_family directly (BSD has sun_len first) */
++		servlen = offsetof(struct sockaddr_un, sun_path) + strlen(fcgi_addr_un.sun_path);
++
+ 		socket_type = AF_UNIX;
+ 		fcgi_addr = (struct sockaddr *) &fcgi_addr_un;
+ 
+-- 
+2.56.0
+