open: input validation for empty segments in path#5950
Merged
Conversation
Member
Yeah, I think that's probably a nice approach. Maybe we shouldn't reuse What do you think about... diff --git a/CMakeLists.txt b/CMakeLists.txt
index 655697979..04972d0fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,6 +49,7 @@ OPTION(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF)
OPTION(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF)
OPTION(USE_LEAK_CHECKER "Run tests with leak checker" OFF)
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
+OPTION(DEBUG_STRICT_OPEN "Enable strict validation on open(2)" 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.")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4fde16d8a..1812bb740 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,11 @@ IF(DEBUG_POOL)
ENDIF()
ADD_FEATURE_INFO(debugpool GIT_DEBUG_POOL "debug pool allocator")
+IF(DEBUG_STRICT_OPEN)
+ SET(GIT_DEBUG_STRICT_OPEN 1)
+ENDIF()
+ADD_FEATURE_INFO(debugopen GIT_DEBUG_STRICT_OPEN "debug strict open validation")
+
INCLUDE(PkgBuildConfig)
INCLUDE(SanitizeBool)
diff --git a/src/features.h.in b/src/features.h.in
index c8d01804f..98f728194 100644
--- a/src/features.h.in
+++ b/src/features.h.in
@@ -2,6 +2,8 @@
#define INCLUDE_features_h__
#cmakedefine GIT_DEBUG_POOL 1
+#cmakedefine GIT_DEBUG_STRICT_OPEN 1
+
#cmakedefine GIT_TRACE 1
#cmakedefine GIT_THREADS 1
#cmakedefine GIT_WIN32_LEAKCHECK 1and using that as the invariant for |
Member
|
(See what I did over in #5951 in case that illustrates better what I mean.) |
b0986ce to
847713f
Compare
Member
|
Neat! Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As mentioned in issue #5920 there are a couple of places that tries to open paths containing empty path segments.
It would be nice if this could be caught in testing.
This PR uses the linker to overload the open() function and tests path for empty segment.
The idea is that we could add input validation to more POSIX calls to catch usage that is implementation defined or have unspecified behavior.
Maybe there is a more generic way to test for this?
We could check for _DEBUG and add the test to the p_open() function and let it fail if the path looks malformed.
Unfortunately that wouldn't have any impact on test cases where p_open() is expected to fail for other reasons but maybe that is a smaller problem.