From: Joe Orton Date: Wed, 2 Oct 2019 09:58:01 +0000 (+0000) Subject: * modules/generators/mod_cgid.c (sock_readhdr): Only set up control X-Git-Tag: 2.5.0-alpha2-ci-test-only~1882 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2715cad0f948b0c7b53f1b8f24526d9971842e90;p=thirdparty%2Fapache%2Fhttpd.git * modules/generators/mod_cgid.c (sock_readhdr): Only set up control message block when required; add some additional error handling. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1867878 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 67f458a27e0..4354499b4f4 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -381,11 +381,12 @@ static apr_status_t sock_readhdr(int fd, int *errfd, void *vbuf, size_t buf_size msg.msg_iov = &vec; msg.msg_iovlen = 1; - - msg.msg_control = u.buf; - msg.msg_controllen = sizeof(u.buf); - if (errfd) *errfd = 0; + if (errfd) { + msg.msg_control = u.buf; + msg.msg_controllen = sizeof(u.buf); + *errfd = 0; + } /* use MSG_WAITALL to skip loop on truncated reads */ do { @@ -395,10 +396,17 @@ static apr_status_t sock_readhdr(int fd, int *errfd, void *vbuf, size_t buf_size if (rc == 0) { return ECONNRESET; } - - cmsg = CMSG_FIRSTHDR(&msg); + else if (rc < 0) { + return errno; + } + else if (rc != buf_size) { + /* MSG_WAITALL should ensure the recvmsg blocks until the + * entire length is read, but let's be paranoid. */ + return APR_INCOMPLETE; + } + if (errfd - && cmsg + && (cmsg = CMSG_FIRSTHDR(&msg)) != NULL && cmsg->cmsg_len == CMSG_LEN(sizeof(*errfd)) && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {