swtpm: Use write_full instead of plain write

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Stefan Berger 2019-07-12 17:04:39 -04:00 committed by Stefan Berger
parent 2d921e663c
commit ec355ee80c
2 changed files with 6 additions and 10 deletions

View File

@ -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;

View File

@ -51,6 +51,7 @@
#include <stdbool.h>
#include "logging.h"
#include "utils.h"
#include <libtpms/tpm_library.h>
@ -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;