Skip to content

Commit

Permalink
[posix] update the max size of file path to PATH_MAX (#10622)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhanglongxia authored Aug 19, 2024
1 parent 4e053fe commit fb7b457
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/posix/platform/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/posix/platform/config_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define OT_POSIX_PLATFORM_CONFIG_FILE_HPP_

#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include <openthread/error.h>

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit fb7b457

Please sign in to comment.