Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open: input validation for empty segments in path #5950

Merged
merged 3 commits into from
Aug 25, 2021

Conversation

boretrk
Copy link
Contributor

@boretrk boretrk commented Jul 18, 2021

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.

@ethomson
Copy link
Member

ethomson commented Jul 19, 2021

We could check for _DEBUG and add the test to the p_open() function and let it fail if the path looks malformed.

Yeah, I think that's probably a nice approach. Maybe we shouldn't reuse DEBUG, and instead add a new GIT_DEBUG_STRICT_OPEN...

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 1

and using that as the invariant for popen?

@ethomson
Copy link
Member

(See what I did over in #5951 in case that illustrates better what I mean.)

@boretrk boretrk changed the title clar: Test open() call for empty path segments open: input validation for empty segments in path Aug 7, 2021
@boretrk boretrk force-pushed the posixtest branch 2 times, most recently from b0986ce to 847713f Compare August 7, 2021 13:36
@ethomson
Copy link
Member

Neat! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants