diff options
| author | Peter Pettersson <boretrk@hotmail.com> | 2021-08-08 13:22:53 +0200 |
|---|---|---|
| committer | Peter Pettersson <boretrk@hotmail.com> | 2021-08-08 13:26:24 +0200 |
| commit | e96fc0283aea9afd02f64bdcb26613422e74dc3a (patch) | |
| tree | 6eb38e100ef9d7b098ed42ba27d34938cac0dc9d /src | |
| parent | e65229ee972c113413eeca77853213352129bd47 (diff) | |
| download | libgit2-e96fc0283aea9afd02f64bdcb26613422e74dc3a.tar.gz | |
tests: optional test for p_open() with empty path segments
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/features.h.in | 1 | ||||
| -rw-r--r-- | src/posix.c | 7 | ||||
| -rw-r--r-- | src/win32/posix_w32.c | 7 |
4 files changed, 20 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3408999f..54099c384 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,11 @@ IF(DEBUG_STRICT_ALLOC) ENDIF() ADD_FEATURE_INFO(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators") +IF(DEBUG_STRICT_OPEN) + SET(GIT_DEBUG_STRICT_OPEN 1) +ENDIF() +ADD_FEATURE_INFO(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open") + INCLUDE(PkgBuildConfig) INCLUDE(SanitizeBool) diff --git a/src/features.h.in b/src/features.h.in index ab523f90b..21e5fdc07 100644 --- a/src/features.h.in +++ b/src/features.h.in @@ -3,6 +3,7 @@ #cmakedefine GIT_DEBUG_POOL 1 #cmakedefine GIT_DEBUG_STRICT_ALLOC 1 +#cmakedefine GIT_DEBUG_STRICT_OPEN 1 #cmakedefine GIT_TRACE 1 #cmakedefine GIT_THREADS 1 diff --git a/src/posix.c b/src/posix.c index bf764ae6b..c40134824 100644 --- a/src/posix.c +++ b/src/posix.c @@ -109,6 +109,13 @@ int p_open(const char *path, volatile int flags, ...) { mode_t mode = 0; + #ifdef GIT_DEBUG_STRICT_OPEN + if (strstr(path, "//") != NULL) { + errno = EACCES; + return -1; + } + #endif + if (flags & O_CREAT) { va_list arg_list; diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 0a8f2bee0..7fcc472e9 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -543,6 +543,13 @@ int p_open(const char *path, int flags, ...) mode_t mode = 0; struct open_opts opts = {0}; + #ifdef GIT_DEBUG_STRICT_OPEN + if (strstr(path, "//") != NULL) { + errno = EACCES; + return -1; + } + #endif + if (git_win32_path_from_utf8(wpath, path) < 0) return -1; |
