svn commit: r1935193 - httpd/httpd/trunk/modules/generators

[email protected] Thu, 11 Jun 2026 11:38:42 -0000
Newsgroups gmane.comp.apache.cvs
Message-ID <178117792222.756649.16099962403692783293@svn03-he-fi>
Author: jorton
Date: Thu Jun 11 11:38:41 2026
New Revision: 1935193

Log:
* modules/generators/mod_cgid.c (close_unix_socket): Return errno
  on failure rather than -1.
  (sock_write): Handle short writes.
  (cgid_init): Fix off-by-one in socket path truncation.

Assisted-by: Claude Opus 4.6 <[email protected]>
GitHub: resolves PR#669

Modified:
   httpd/httpd/trunk/modules/generators/mod_cgid.c

Modified: httpd/httpd/trunk/modules/generators/mod_cgid.c
==============================================================================
--- httpd/httpd/trunk/modules/generators/mod_cgid.c	Thu Jun 11 11:38:22 2026	(r1935192)
+++ httpd/httpd/trunk/modules/generators/mod_cgid.c	Thu Jun 11 11:38:41 2026	(r1935193)
@@ -344,7 +344,7 @@ static apr_status_t close_unix_socket(vo
 {
     int fd = (int)((long)thefd);
 
-    return close(fd);
+    return close(fd) < 0 ? errno : APR_SUCCESS;
 }
 
 /* Read from the socket dealing with incomplete messages and signals.
@@ -433,13 +433,18 @@ static apr_status_t sock_read(int fd, vo
 static apr_status_t sock_write(int fd, const void *buf, size_t buf_size)
 {
     int rc;
+    const char *b = buf;
+    size_t written = 0;
 
     do {
-        rc = write(fd, buf, buf_size);
-    } while (rc < 0 && errno == EINTR);
-    if (rc < 0) {
-        return errno;
-    }
+        do {
+            rc = write(fd, b + written, buf_size - written);
+        } while (rc < 0 && errno == EINTR);
+        if (rc < 0) {
+            return errno;
+        }
+        written += rc;
+    } while (written < buf_size);
 
     return APR_SUCCESS;
 }
@@ -1078,7 +1083,7 @@ static int cgid_init(apr_pool_t *p, apr_
             return DECLINED;
         }
         if (strlen(tmp_sockname) > sizeof(server_addr->sun_path) - 1) {
-            tmp_sockname[sizeof(server_addr->sun_path)] = '\0';
+            tmp_sockname[sizeof(server_addr->sun_path) - 1] = '\0';
             ap_log_error(APLOG_MARK, APLOG_ERR, 0, main_server, APLOGNO(01254)
                         "The length of the ScriptSock path exceeds maximum, "
                         "truncating to %s", tmp_sockname);