diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2021-03-20 14:28:25 +0000 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2021-04-28 13:03:33 +0100 |
| commit | dbc03de479eec4f96ce3273bf76f49daccbeb496 (patch) | |
| tree | 0ada4cf3ec1b92175b20d7be13082d1b468eba97 | |
| parent | dc1ba018289aa40e1948a5fbb673652f86170677 (diff) | |
| download | libgit2-dbc03de479eec4f96ce3273bf76f49daccbeb496.tar.gz | |
apply: ensure we validate paths
There was no test ensuring that we validate `.git` paths. We do, but
let's add a test to make sure that we never regress this.
| -rw-r--r-- | src/path.c | 4 | ||||
| -rw-r--r-- | tests/apply/apply_helpers.h | 9 | ||||
| -rw-r--r-- | tests/apply/both.c | 11 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/path.c b/src/path.c index a4c289e16..50a0b468c 100644 --- a/src/path.c +++ b/src/path.c @@ -1923,7 +1923,7 @@ GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) int git_path_validate_workdir(git_repository *repo, const char *path) { if (should_validate_longpaths(repo)) - return git_path_validate_ondisk(path, strlen(path)); + return git_path_validate_filesystem(path, strlen(path)); return 0; } @@ -1934,7 +1934,7 @@ int git_path_validate_workdir_with_len( size_t path_len) { if (should_validate_longpaths(repo)) - return git_path_validate_ondisk(path, path_len); + return git_path_validate_filesystem(path, path_len); return 0; } diff --git a/tests/apply/apply_helpers.h b/tests/apply/apply_helpers.h index 2d0019abf..82094773e 100644 --- a/tests/apply/apply_helpers.h +++ b/tests/apply/apply_helpers.h @@ -474,6 +474,15 @@ "-asparagus which had been laid by, boil it until these last articles are\n" \ "-sufficiently done, thicken with flour, butter and milk, and serve it up.\n" +#define DIFF_ADD_INVALID_FILENAME \ + "diff --git a/.git/hello_world.txt b/.git/hello_world.txt\n" \ + "new file mode 100644\n" \ + "index 0000000..f75ba05\n" \ + "--- /dev/null\n" \ + "+++ b/.git/hello_world.txt\n" \ + "@@ -0,0 +1 @@\n" \ + "+Hello, world.\n" + void validate_apply_workdir( git_repository *repo, struct merge_index_entry *workdir_entries, diff --git a/tests/apply/both.c b/tests/apply/both.c index 400df5e38..108963270 100644 --- a/tests/apply/both.c +++ b/tests/apply/both.c @@ -734,3 +734,14 @@ void test_apply_both__cant_remove_file_twice(void) git_diff_free(diff); } + +void test_apply_both__cant_add_invalid_filename(void) +{ + git_diff *diff; + + cl_git_pass(git_diff_from_buffer(&diff, DIFF_ADD_INVALID_FILENAME, + strlen(DIFF_ADD_INVALID_FILENAME))); + cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL)); + + git_diff_free(diff); +} |
