Skip to content

Commit 8e210c2

Browse files
committed
* 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 <noreply@anthropic.com> GitHub: resolves PR#669 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1935193 13f79535-47bb-0310-9956-ffa450edef68
1 parent 489f5ef commit 8e210c2

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

modules/generators/mod_cgid.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static apr_status_t close_unix_socket(void *thefd)
344344
{
345345
int fd = (int)((long)thefd);
346346

347-
return close(fd);
347+
return close(fd) < 0 ? errno : APR_SUCCESS;
348348
}
349349

350350
/* 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)
433433
static apr_status_t sock_write(int fd, const void *buf, size_t buf_size)
434434
{
435435
int rc;
436+
const char *b = buf;
437+
size_t written = 0;
436438

437439
do {
438-
rc = write(fd, buf, buf_size);
439-
} while (rc < 0 && errno == EINTR);
440-
if (rc < 0) {
441-
return errno;
442-
}
440+
do {
441+
rc = write(fd, b + written, buf_size - written);
442+
} while (rc < 0 && errno == EINTR);
443+
if (rc < 0) {
444+
return errno;
445+
}
446+
written += rc;
447+
} while (written < buf_size);
443448

444449
return APR_SUCCESS;
445450
}
@@ -1078,7 +1083,7 @@ static int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
10781083
return DECLINED;
10791084
}
10801085
if (strlen(tmp_sockname) > sizeof(server_addr->sun_path) - 1) {
1081-
tmp_sockname[sizeof(server_addr->sun_path)] = '\0';
1086+
tmp_sockname[sizeof(server_addr->sun_path) - 1] = '\0';
10821087
ap_log_error(APLOG_MARK, APLOG_ERR, 0, main_server, APLOGNO(01254)
10831088
"The length of the ScriptSock path exceeds maximum, "
10841089
"truncating to %s", tmp_sockname);

0 commit comments

Comments
 (0)