[Tarantool-patches] [PATCH 4/6] xlog: use PATH_MAX for filename

Cyrill Gorcunov gorcunov at gmail.com
Thu Jun 18 01:03:33 MSK 2020


Similar to dirname there is no need for +1 byte.
Same time make sure xlog_open never end up without
trailing zero.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/box/xlog.c | 6 ++++--
 src/box/xlog.h | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/box/xlog.c b/src/box/xlog.c
index 8b2818326..1685a4cf7 100644
--- a/src/box/xlog.c
+++ b/src/box/xlog.c
@@ -822,7 +822,7 @@ xlog_create(struct xlog *xlog, const char *name, int flags,
 
 	xlog->meta = *meta;
 	xlog->is_inprogress = true;
-	snprintf(xlog->filename, PATH_MAX, "%s%s", name, inprogress_suffix);
+	snprintf(xlog->filename, sizeof(xlog->filename), "%s%s", name, inprogress_suffix);
 
 	flags |= O_RDWR | O_CREAT | O_EXCL;
 
@@ -881,7 +881,9 @@ xlog_open(struct xlog *xlog, const char *name, const struct xlog_opts *opts)
 	if (xlog_init(xlog, opts) != 0)
 		goto err;
 
-	strncpy(xlog->filename, name, PATH_MAX);
+	strncpy(xlog->filename, name, sizeof(xlog->filename));
+	xlog->filename[sizeof(xlog->filename)-1] = '\0';
+
 	xlog->fd = open(xlog->filename, O_RDWR);
 	if (xlog->fd < 0) {
 		say_syserror("open, [%s]", name);
diff --git a/src/box/xlog.h b/src/box/xlog.h
index 329d78c77..9ffce598b 100644
--- a/src/box/xlog.h
+++ b/src/box/xlog.h
@@ -352,7 +352,7 @@ struct xlog {
 	 */
 	int64_t tx_rows;
 	/** Log file name. */
-	char filename[PATH_MAX + 1];
+	char filename[PATH_MAX];
 	/** Whether this file has .inprogress suffix. */
 	bool is_inprogress;
 	/*
-- 
2.26.2



More information about the Tarantool-patches mailing list