Skip to content

Commit f99e45c

Browse files
authored
Merge pull request #114 from hfmanson/master
fixed porting errors
2 parents cf088f7 + c73f9b3 commit f99e45c

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/libtlspool.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,13 @@ int tlspool_starttls (int cryptfd, starttls_t *tlsdata,
590590
// printf ("\n");
591591

592592
/* Send the request */
593-
os_sendmsg_command(poolfd, &cmd, renegotiate ? -1 : cryptfd);
593+
if (os_sendmsg_command(poolfd, &cmd, renegotiate ? -1 : cryptfd) == -1) {
594+
// Let SIGPIPE be reported as EPIPE
595+
close (cryptfd);
596+
registry_update (&entry_reqid, NULL);
597+
// errno inherited from os_sendmsg_command()
598+
return -1;
599+
}
594600
sentfd = cryptfd; /* Close anytime after response and before fn end */
595601

596602
/* Handle responses until success or error */
@@ -629,7 +635,16 @@ int tlspool_starttls (int cryptfd, starttls_t *tlsdata,
629635
/* We may now have a value to send in plainfd */
630636
/* Now supply plainfd in the callback response */
631637
sentfd = plainfd;
632-
os_sendmsg_command(poolfd, &cmd, plainfd);
638+
if (os_sendmsg_command(poolfd, &cmd, plainfd) == -1) {
639+
// Let SIGPIPE be reported as EPIPE
640+
if (sentfd >= 0) {
641+
closesocket(sentfd);
642+
sentfd = -1;
643+
}
644+
registry_update (&entry_reqid, NULL);
645+
// errno inherited from np_send_command()
646+
return -1;
647+
}
633648
break; // Loop around and try again
634649
case PIOC_STARTTLS_V2:
635650
/* Wheee!!! we're done */

lib/libtlspool_posix.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ int os_sendmsg_command(pool_handle_t poolfd, struct tlspool_command *cmd, int fd
55
struct iovec iov;
66
struct cmsghdr *cmsg;
77
struct msghdr mh = { 0 };
8-
iov.iov_base = &cmd;
9-
iov.iov_len = sizeof(cmd);
8+
iov.iov_base = cmd;
9+
iov.iov_len = sizeof(struct tlspool_command);
1010
mh.msg_iov = &iov;
1111
mh.msg_iovlen = 1;
1212
if (fd >= 0) {
@@ -19,6 +19,7 @@ int os_sendmsg_command(pool_handle_t poolfd, struct tlspool_command *cmd, int fd
1919
*(int *)CMSG_DATA(cmsg) = fd;
2020
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
2121
}
22+
return sendmsg (poolfd, &mh, MSG_NOSIGNAL);
2223
}
2324

2425

@@ -123,6 +124,6 @@ pool_handle_t open_pool (void *path) {
123124
newpoolfd = INVALID_POOL_HANDLE;
124125
}
125126
}
126-
// printf ("DEBUG: Trying new poolfd %d for path %s\n", poolfd, sun.sun_path);
127+
// printf ("DEBUG: Trying new poolfd %d for path %s\n", newpoolfd, sun.sun_path);
127128
return newpoolfd;
128129
}

0 commit comments

Comments
 (0)