From 5a61c67dbf049e5ba30216822841b9bc797dbeab Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Mon, 19 Aug 2024 09:37:07 +0800 Subject: [PATCH] [posix] update the max size of file path to PATH_MAX The length of the configuration file path may exceed the default defined max length 255. This commit changes the name from `kFileNameMaxSize` to `kFilePathMaxSize` and sets its value to the PATH_MAX. --- src/posix/platform/config_file.cpp | 4 ++-- src/posix/platform/config_file.hpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/posix/platform/config_file.cpp b/src/posix/platform/config_file.cpp index c8a7dddb473..bd48f56a25e 100644 --- a/src/posix/platform/config_file.cpp +++ b/src/posix/platform/config_file.cpp @@ -47,7 +47,7 @@ ConfigFile::ConfigFile(const char *aFilePath) : mFilePath(aFilePath) { assert(mFilePath != nullptr); - VerifyOrDie(strlen(mFilePath) + strlen(kSwapSuffix) < kFileNameMaxSize, OT_EXIT_FAILURE); + VerifyOrDie(strlen(mFilePath) + strlen(kSwapSuffix) < kFilePathMaxSize, OT_EXIT_FAILURE); } bool ConfigFile::HasKey(const char *aKey) const @@ -163,7 +163,7 @@ otError ConfigFile::Add(const char *aKey, const char *aValue) otError ConfigFile::Clear(const char *aKey) { otError error = OT_ERROR_NONE; - char swapFile[kFileNameMaxSize]; + char swapFile[kFilePathMaxSize]; char line[kLineMaxSize]; FILE *fp = nullptr; FILE *fpSwap = nullptr; diff --git a/src/posix/platform/config_file.hpp b/src/posix/platform/config_file.hpp index 1590ed284d4..71038f41167 100644 --- a/src/posix/platform/config_file.hpp +++ b/src/posix/platform/config_file.hpp @@ -30,6 +30,7 @@ #define OT_POSIX_PLATFORM_CONFIG_FILE_HPP_ #include +#include #include #include @@ -115,7 +116,7 @@ class ConfigFile const char *kCommentDelimiter = "#"; const char *kSwapSuffix = ".swap"; static constexpr uint16_t kLineMaxSize = 512; - static constexpr uint16_t kFileNameMaxSize = 255; + static constexpr uint16_t kFilePathMaxSize = PATH_MAX; void Strip(char *aString) const;