diff options
| author | Christian Brauner <brauner@kernel.org> | 2025-06-12 16:25:19 +0300 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2025-06-16 18:01:22 +0300 |
| commit | 0da3e3822cfabf062945e449f91ea3ca529eeaa4 (patch) | |
| tree | c9c72d541b60f9b9a84b354af39371aa85daa2a9 /include/linux/fs.h | |
| parent | 3a2c977c463c68bf6fcd0138d15efa5f3adc743c (diff) | |
| download | linux-0da3e3822cfabf062945e449f91ea3ca529eeaa4.tar.xz | |
fs: move name_contains_dotdot() to header
Move the helper from the firmware specific code to a header so we can
reuse it for coredump sockets.
Link: https://lore.kernel.org/20250612-work-coredump-massage-v1-5-315c0c34ba94@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'include/linux/fs.h')
| -rw-r--r-- | include/linux/fs.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index 96c7925a6551..18fdbd184eea 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3264,6 +3264,22 @@ static inline bool is_dot_dotdot(const char *name, size_t len) (len == 1 || (len == 2 && name[1] == '.')); } +/** + * name_contains_dotdot - check if a file name contains ".." path components + * + * Search for ".." surrounded by either '/' or start/end of string. + */ +static inline bool name_contains_dotdot(const char *name) +{ + size_t name_len; + + name_len = strlen(name); + return strcmp(name, "..") == 0 || + strncmp(name, "../", 3) == 0 || + strstr(name, "/../") != NULL || + (name_len >= 3 && strcmp(name + name_len - 3, "/..") == 0); +} + #include <linux/err.h> /* needed for stackable file system support */ |
