From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E4A5942EF5D for ; Thu, 18 Jun 2020 01:04:30 +0300 (MSK) Received: by mail-lf1-f67.google.com with SMTP id d21so177705lfb.6 for ; Wed, 17 Jun 2020 15:04:30 -0700 (PDT) From: Cyrill Gorcunov Date: Thu, 18 Jun 2020 01:03:33 +0300 Message-Id: <20200617220335.836265-5-gorcunov@gmail.com> In-Reply-To: <20200617220335.836265-1-gorcunov@gmail.com> References: <20200617220335.836265-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 4/6] xlog: use PATH_MAX for filename List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Cc: Vladislav Shpilevoy , Alexander Turenko 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 --- 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