From ec355ee80cc7f79d441b10c538a2bc17741ae828 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 12 Jul 2019 17:04:39 -0400 Subject: [PATCH] swtpm: Use write_full instead of plain write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Berger Reviewed-by: Marc-André Lureau --- src/swtpm/ctrlchannel.c | 11 +++-------- src/swtpm/logging.c | 5 +++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/swtpm/ctrlchannel.c b/src/swtpm/ctrlchannel.c index 4f046db..ca0c4cf 100644 --- a/src/swtpm/ctrlchannel.c +++ b/src/swtpm/ctrlchannel.c @@ -183,7 +183,7 @@ static int ctrlchannel_return_state(ptm_getstate *pgs, int fd) iov[1].iov_base, min(iov[1].iov_len, 1024)); } - n = writev(fd, iov, iovcnt); + n = writev_full(fd, iov, iovcnt); if (n < 0) { logprintf(STDERR_FILENO, "Error: Could not send response: %s\n", strerror(errno)); @@ -247,7 +247,7 @@ static int ctrlchannel_receive_state(ptm_setstate *pss, ssize_t n, int fd) err_send_resp: pss->u.resp.tpm_result = htobe32(res); - n = write(fd, pss, sizeof(pss->u.resp.tpm_result)); + n = write_full(fd, pss, sizeof(pss->u.resp.tpm_result)); if (n < 0) { logprintf(STDERR_FILENO, "Error: Could not send response: %s\n", strerror(errno)); @@ -864,17 +864,12 @@ int ctrlchannel_process_fd(int fd, send_resp: TPM_PrintAll(" Ctrl Rsp:", " ", output.body, min(out_len, 1024)); - n = write(fd, output.body, out_len); + n = write_full(fd, output.body, out_len); if (n < 0) { logprintf(STDERR_FILENO, "Error: Could not send response: %s\n", strerror(errno)); close(fd); fd = -1; - } else if ((size_t)n != out_len) { - logprintf(STDERR_FILENO, - "Error: Could not send complete response\n"); - close(fd); - fd = -1; } return fd; diff --git a/src/swtpm/logging.c b/src/swtpm/logging.c index 5cccdb3..522fe6d 100644 --- a/src/swtpm/logging.c +++ b/src/swtpm/logging.c @@ -51,6 +51,7 @@ #include #include "logging.h" +#include "utils.h" #include @@ -245,12 +246,12 @@ static int _logprintf(int fd, const char *format, va_list ap, bool check_indent) if (!check_indent || log_check_string(buf) >= 0) { if (log_prefix) { - ret = write(fd, log_prefix, strlen(log_prefix)); + ret = write_full(fd, log_prefix, strlen(log_prefix)); if (ret < 0) goto err_exit; len = ret; } - ret = write(fd, buf, strlen(buf)); + ret = write_full(fd, buf, strlen(buf)); if (ret < 0) goto err_exit; ret += len;