From: Joe Orton Date: Thu, 11 Jun 2026 11:38:41 +0000 (+0000) Subject: * modules/generators/mod_cgid.c (close_unix_socket): Return errno X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8e210c28a1dfd84a1e9c4fb8fd3d646619639dfd;p=thirdparty%2Fapache%2Fhttpd.git * 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 GitHub: resolves PR#669 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1935193 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index b20f4484f3..42bd384c20 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -344,7 +344,7 @@ static apr_status_t close_unix_socket(void *thefd) { 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, void *vbuf, size_t buf_size) 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_pool_t *plog, apr_pool_t *ptemp, 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);