All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
To: axboe@kernel.dk, fio@vger.kernel.org
Cc: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Subject: [PATCH 3/4] Null terminate before (or after) strncpy(3)
Date: Sat, 30 Jul 2016 00:05:59 +0900	[thread overview]
Message-ID: <1469804760-17333-3-git-send-email-kusumi.tomohiro@gmail.com> (raw)
In-Reply-To: <1469804760-17333-1-git-send-email-kusumi.tomohiro@gmail.com>

These three strncpy() calls copy at most sizeof(buffer)-1 bytes,
but buffer isn't explicitly 0 cleared, so 0 terminate the last byte.

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
---
 diskutil.c  |    2 ++
 ioengines.c |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/diskutil.c b/diskutil.c
index 294d2d3..a1077d4 100644
--- a/diskutil.c
+++ b/diskutil.c
@@ -179,6 +179,7 @@ static int get_device_numbers(char *file_name, int *maj, int *min)
 		/*
 		 * must be a file, open "." in that path
 		 */
+		tempname[PATH_MAX - 1] = '\0';
 		strncpy(tempname, file_name, PATH_MAX - 1);
 		p = dirname(tempname);
 		if (stat(p, &st)) {
@@ -426,6 +427,7 @@ static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
 			log_err("unknown sysfs layout\n");
 			return NULL;
 		}
+		tmp[PATH_MAX - 1] = '\0';
 		strncpy(tmp, p, PATH_MAX - 1);
 		sprintf(path, "%s", tmp);
 	}
diff --git a/ioengines.c b/ioengines.c
index 918b50a..f7b5ed6 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -130,6 +130,7 @@ struct ioengine_ops *load_ioengine(struct thread_data *td, const char *name)
 
 	dprint(FD_IO, "load ioengine %s\n", name);
 
+	engine[sizeof(engine) - 1] = '\0';
 	strncpy(engine, name, sizeof(engine) - 1);
 
 	/*
-- 
1.7.1



  parent reply	other threads:[~2016-07-29 15:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-29 15:05 [PATCH 1/4] Use in-place path separator "/" for Linux specific code Tomohiro Kusumi
2016-07-29 15:02 ` Jens Axboe
2016-07-29 15:40   ` Tomohiro Kusumi
2016-07-29 15:05 ` [PATCH 2/4] Make switch_ioscheduler() return 0 if FIO_HAVE_IOSCHED_SWITCH is undefined Tomohiro Kusumi
2016-07-29 15:05 ` Tomohiro Kusumi [this message]
2016-07-29 15:06 ` [PATCH 4/4] Use larger local buffer for I/O engine name Tomohiro Kusumi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469804760-17333-3-git-send-email-kusumi.tomohiro@gmail.com \
    --to=kusumi.tomohiro@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=fio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.