From 41ba28892a04ab8a35a2751b4b7801414706f284 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 6 May 2021 16:49:09 -0400 Subject: Forget about ARG_MAX. The likelihood of accepting an unfathomably large input from the environment is pretty low --- CMakeLists.txt | 3 --- config.h.in | 3 +-- include/cleanpath.h | 5 +++++ lib/cleanpath.c | 14 +------------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04e6239..5929cff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,6 @@ set(LIB_SOURCES lib/cleanpath.c) set(MAIN_SOURCES src/main.c) set(INCLUDES include/cleanpath.h) -CHECK_INCLUDE_FILE(sys/limits.h HAVE_SYS_LIMIT_H) -CHECK_INCLUDE_FILE(linux/limits.h HAVE_LINUX_LIMIT_H) - configure_file ("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/include/config.h") diff --git a/config.h.in b/config.h.in index f8a0396..777f43c 100644 --- a/config.h.in +++ b/config.h.in @@ -1,7 +1,6 @@ #ifndef CLEAN_PATH_CONFIG_H #define CLEAN_PATH_CONFIG_H -#cmakedefine HAVE_SYS_LIMIT_H @HAVE_SYS_LIMIT_H@ -#cmakedefine HAVE_LINUX_LIMIT_H @HAVE_LINUX_LIMIT_H@ +// Reserved for later use #endif \ No newline at end of file diff --git a/include/cleanpath.h b/include/cleanpath.h index 321f921..6d50db4 100644 --- a/include/cleanpath.h +++ b/include/cleanpath.h @@ -36,6 +36,11 @@ #define CLEANPATH_VAR "PATH" #define CLEANPATH_SEP ":" +#if OS_WINDOWS +#undef CLEANPATH_SEP +#define CLEANPATH_SEP ";" +#endif + struct CleanPath { char *data; // Pointer to the path string size_t data_len; // Length of the path string diff --git a/lib/cleanpath.c b/lib/cleanpath.c index c7f8bc9..b849199 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -4,18 +4,6 @@ #include "config.h" #include "cleanpath.h" -#if OS_LINUX -#if HAVE_SYS_LIMIT_H -#include -#endif // HAVE_SYS_LIMIT_H - -#if HAVE_LINUX_LIMIT_H -#include -#endif // HAVE_LINUX_LIMIT_H -#else -#include -#endif - /** * Split path into parts by sep * @param path a string (e.g. "/path1:/path2:/pathN") @@ -33,7 +21,7 @@ struct CleanPath *cleanpath_init(const char *path, const char *sep) { } result = calloc(1, sizeof(*result)); - result->data = strndup(path, ARG_MAX); + result->data = strdup(path); result->data_len = strlen(result->data) + 2; // + 2 to handle an empty PATH result->sep = strdup(sep); -- cgit