Skip to content

Commit e96fc02

Browse files
committed
tests: optional test for p_open() with empty path segments
1 parent e65229e commit e96fc02

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
env:
8787
CC: gcc
8888
CMAKE_GENERATOR: Ninja
89-
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DDEBUG_STRICT_ALLOC=ON
89+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
9090
os: ubuntu-latest
9191
- # Xenial, GCC, mbedTLS
9292
container:

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ OPTION(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)"
5151
OPTION(USE_LEAK_CHECKER "Run tests with leak checker" OFF)
5252
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
5353
OPTION(DEBUG_STRICT_ALLOC "Enable strict allocator behavior" OFF)
54+
OPTION(DEBUG_STRICT_OPEN "Enable path validation in open" OFF)
5455
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
5556
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib. Can be set to one of Bundled(ON)/Chromium. The Chromium option requires a x86_64 processor with SSE4.2 and CLMUL" OFF)
5657
SET(USE_HTTP_PARSER "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ IF(DEBUG_STRICT_ALLOC)
1111
ENDIF()
1212
ADD_FEATURE_INFO(debugalloc GIT_DEBUG_STRICT_ALLOC "debug strict allocators")
1313

14+
IF(DEBUG_STRICT_OPEN)
15+
SET(GIT_DEBUG_STRICT_OPEN 1)
16+
ENDIF()
17+
ADD_FEATURE_INFO(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
18+
1419
INCLUDE(PkgBuildConfig)
1520
INCLUDE(SanitizeBool)
1621

src/features.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#cmakedefine GIT_DEBUG_POOL 1
55
#cmakedefine GIT_DEBUG_STRICT_ALLOC 1
6+
#cmakedefine GIT_DEBUG_STRICT_OPEN 1
67

78
#cmakedefine GIT_TRACE 1
89
#cmakedefine GIT_THREADS 1

src/posix.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ int p_open(const char *path, volatile int flags, ...)
109109
{
110110
mode_t mode = 0;
111111

112+
#ifdef GIT_DEBUG_STRICT_OPEN
113+
if (strstr(path, "//") != NULL) {
114+
errno = EACCES;
115+
return -1;
116+
}
117+
#endif
118+
112119
if (flags & O_CREAT) {
113120
va_list arg_list;
114121

src/win32/posix_w32.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,13 @@ int p_open(const char *path, int flags, ...)
543543
mode_t mode = 0;
544544
struct open_opts opts = {0};
545545

546+
#ifdef GIT_DEBUG_STRICT_OPEN
547+
if (strstr(path, "//") != NULL) {
548+
errno = EACCES;
549+
return -1;
550+
}
551+
#endif
552+
546553
if (git_win32_path_from_utf8(wpath, path) < 0)
547554
return -1;
548555

0 commit comments

Comments
 (0)