Skip to content

Commit

Permalink
Optional test for open() with empty path segments
Browse files Browse the repository at this point in the history
  • Loading branch information
boretrk committed Aug 7, 2021
1 parent e65229e commit 847713f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ OPTION(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)"
OPTION(USE_LEAK_CHECKER "Run tests with leak checker" OFF)
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
OPTION(DEBUG_STRICT_ALLOC "Enable strict allocator behavior" OFF)
OPTION(DEBUG_STRICT_OPEN "Enable path validation in open" OFF)
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
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)
SET(USE_HTTP_PARSER "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/features.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions src/win32/posix_w32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 847713f

Please sign in to comment.