[Tarantool-patches] [PATCH 5/6] xlog: xlog_cursor -- use sizeof with snprintf for safety

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


This is more consistent than relying that array size
will remain PATH_MAX forever.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/box/xlog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/box/xlog.c b/src/box/xlog.c
index 1685a4cf7..94f7838bf 100644
--- a/src/box/xlog.c
+++ b/src/box/xlog.c
@@ -1970,7 +1970,7 @@ xlog_cursor_openfd(struct xlog_cursor *i, int fd, const char *name)
 		diag_set(XlogError, "Unexpected end of file, run with 'force_recovery = true'");
 		goto error;
 	}
-	snprintf(i->name, PATH_MAX, "%s", name);
+	snprintf(i->name, sizeof(i->name), "%s", name);
 	i->zdctx = ZSTD_createDStream();
 	if (i->zdctx == NULL) {
 		diag_set(ClientError, ER_DECOMPRESSION,
@@ -2027,7 +2027,7 @@ xlog_cursor_openmem(struct xlog_cursor *i, const char *data, size_t size,
 		diag_set(XlogError, "Unexpected end of file");
 		goto error;
 	}
-	snprintf(i->name, PATH_MAX, "%s", name);
+	snprintf(i->name, sizeof(i->name), "%s", name);
 	i->zdctx = ZSTD_createDStream();
 	if (i->zdctx == NULL) {
 		diag_set(ClientError, ER_DECOMPRESSION,
-- 
2.26.2



More information about the Tarantool-patches mailing list