From fb7b457ab225f9a5b32c359b47eaf51a9f73a46a Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Tue, 20 Aug 2024 02:24:59 +0800 Subject: [PATCH] [posix] update the max size of file path to PATH_MAX (#10622) 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 c8a7dddb4..bd48f56a2 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 @@ exit: 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 1590ed284..71038f411 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 @@ private: 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;