From 291ff4889a7d4649bf1079c57e5f77406459778f Mon Sep 17 00:00:00 2001 From: fixthething <79883270+fixthething@users.noreply.github.com> Date: Sat, 6 Mar 2021 11:56:41 -0500 Subject: [PATCH] Doing dword alignment whether source of misalignment comes from file size or specified transfer length. Zeroing buffer to ensure zero fill and no heap garbage. --- nvme.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nvme.c b/nvme.c index b0ccd8e9..4968c212 100644 --- a/nvme.c +++ b/nvme.c @@ -3993,16 +3993,13 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p if (fd < 0) goto ret; - if ((cfg.tl & 3) != 0) - fprintf(stderr, "WARNING: transfer length not dword-aligned; data will be truncated\n"); - if (strlen(cfg.file) == 0) { sec_fd = STDIN_FILENO; if (cfg.tl || ioctl(sec_fd, FIONREAD, &nread) < 0) sec_size = cfg.tl; else - sec_size = ((unsigned int) nread + 3) & ~3; // align to avoid truncation + sec_size = (unsigned int) nread; } else { sec_fd = open(cfg.file, O_RDONLY); if (sec_fd < 0) { @@ -4022,6 +4019,7 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p } buf_size = cfg.tl ? cfg.tl : sec_size; + buf_size = (buf_size + 3) & ~3; // dword align to avoid truncation if (posix_memalign(&sec_buf, getpagesize(), buf_size)) { fprintf(stderr, "No memory for security size:%d\n", buf_size); @@ -4029,6 +4027,8 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p goto close_sec_fd; } + memset(sec_buf, 0, buf_size); // ensure zero fill if buf_size > sec_size + err = read(sec_fd, sec_buf, sec_size); if (err < 0) { err = -errno; -- 2.50.1