mark t3701-add-interactive.sh as leak-free
cover mark t3701-add-interactive.sh as leak-free
Rubén Justo (4):
apply: plug a leak in apply_data
add-interactive: plug a leak in get_untracked_files
add-patch: plug a leak handling the '/' command
add: plug a leak on interactive_add
add-interactive.c | 1 + add-patch.c | 1 + apply.c | 4 +++- builtin/add.c | 9 ++++++--- t/t2016-checkout-patch.sh | 1 + t/t3701-add-interactive.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 14 files changed, 23 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.0.rc0.4.g08f77eb516
PATCH 1/4 apply: plug a leak in apply_data
Plug a leak we have since cfb6f9acc3 (apply: accept -3/--3way command line option, 2012-05-08).
This leak can be triggered with:
$ echo foo >file
$ git add file && git commit -m file
$ echo bar >file
$ git diff file >diff
$ sed s/foo/frotz/ <diff >baddiff
$ git apply --cached <baddiffFixing this leak allows us to mark as leak-free the following tests:
+ t2016-checkout-patch.sh
+ t4103-apply-binary.sh
+ t4104-apply-boundary.sh
+ t4113-apply-ending.sh
+ t4117-apply-reject.sh
+ t4123-apply-shrink.sh
+ t4252-am-options.sh
+ t4258-am-quoted-cr.sh
Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
--- apply.c | 4 +++- t/t2016-checkout-patch.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + 9 files changed, 12 insertions(+), 1 deletion(-)
apply.c +3 -1
@@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,fprintf (stderr,_ ("Falling back to direct application...\n" ));/* Note: with --reject, apply_fragments() returns 0 */ -if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) +if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) { +clear_image (&image);return -1 ; + } } patch->result = image.buf; patch->resultsize = image.len;
t/t2016-checkout-patch.sh +1 -0
@@ -2,6 +2,7 @@ test_description='git checkout --patch' +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success 'setup' '
t/t4103-apply-binary.sh +1 -0
@@ -9,6 +9,7 @@ test_description='git apply handling binary patches GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' '
t/t4104-apply-boundary.sh +1 -0
@@ -5,6 +5,7 @@ test_description='git apply boundary tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh L="c d e f g h i j k l m n o p q r s t u v w x"
t/t4113-apply-ending.sh +1 -0
@@ -6,6 +6,7 @@ test_description='git apply trying to add an ending line. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # setup
t/t4117-apply-reject.sh +1 -0
@@ -7,6 +7,7 @@ test_description='git apply with rejects ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup '
t/t4123-apply-shrink.sh +1 -0
@@ -2,6 +2,7 @@ test_description='apply a patch that is larger than the preimage' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >F <<\EOF
t/t4252-am-options.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with options and not losing them' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh tm="$TEST_DIRECTORY/t4252"
t/t4258-am-quoted-cr.sh +1 -0
@@ -2,6 +2,7 @@ test_description='test am --quoted-cr=<action>' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t4258"
Signature · 1 line
2.45.0.rc0.4.g08f77eb516
Re: [PATCH 1/4] apply: plug a leak in apply_data
Hi Rubén
Quoted 2 lines · Rubén Justo
Plug a leak we have since
cfb6f9acc3(apply: accept -3/--3way command line option, 2012-05-08).
Looking at that commit I see
- if (apply_fragments(&image, patch) < 0)
- return -1; /* note with --reject this succeeds. */
+ if (apply_fragments(&image, patch) < 0) {
+ /* Note: with --reject, apply_fragments() returns 0 */
+ if (!threeway || try_threeway(&image, patch, st, ce) < 0)
+ return -1;
+ }
So the leak existed before that commit. Indeed it looks like the leak predates the introduction of struct image in b94f2eda99 (builtin-apply.c: make it more line oriented, 2008-01-26) and when the patch does not apply we have been leaking the buffer passed to apply_fragments() since the beginning of the builtin apply added in ac6245e31a3 (Builtin git-apply., 2006-05-23)
The fix itself looks good to me
Best Wishes
Phillip
Quoted 150 lines
This leak can be triggered with:
$ echo foo >file $ git add file && git commit -m file $ echo bar >file $ git diff file >diff $ sed s/foo/frotz/ <diff >baddiff $ git apply --cached <baddiffénFixing this leak allows us to mark as leak-free the following tests:
+
t2016-checkout-patch.sh
+t4103-apply-binary.sh
+t4104-apply-boundary.sh
+t4113-apply-ending.sh
+t4117-apply-reject.sh
+t4123-apply-shrink.sh
+t4252-am-options.sh
+t4258-am-quoted-cr.shMark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
Signed-off-by Rubén Justo <[email protected]>--- apply.c | 4 +++- t/t2016-checkout-patch.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + 9 files changed, 12 insertions(+), 1 deletion(-)apply.c +3
-1@@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,fprintf (stderr,_ ("Falling back to direct application...\n" ));/* Note: with --reject, apply_fragments() returns 0 */ -if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) +if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) { +clear_image (&image);return -1 ; + } } patch->result = image.buf; patch->resultsize = image.len;t/t2016-checkout-patch.sh +1
-0@@ -2,6 +2,7 @@ test_description='git checkout --patch' +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success 'setup' 't/t4103-apply-binary.sh +1
-0@@ -9,6 +9,7 @@ test_description='git apply handling binary patches GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' 't/t4104-apply-boundary.sh +1
-0@@ -5,6 +5,7 @@ test_description='git apply boundary tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh L="c d e f g h i j k l m n o p q r s t u v w x"t/t4113-apply-ending.sh +1
-0@@ -6,6 +6,7 @@ test_description='git apply trying to add an ending line. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # setupt/t4117-apply-reject.sh +1
-0@@ -7,6 +7,7 @@ test_description='git apply with rejects ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup 't/t4123-apply-shrink.sh +1
-0@@ -2,6 +2,7 @@ test_description='apply a patch that is larger than the preimage' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >F <<\EOFt/t4252-am-options.sh +2
-0@@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with options and not losing them' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh tm="$TEST_DIRECTORY/t4252"t/t4258-am-quoted-cr.sh +1
-0@@ -2,6 +2,7 @@ test_description='test am --quoted-cr=<action>' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t4258"
Re: [PATCH 1/4] apply: plug a leak in apply_data
Quoted 14 lines · Phillip Wood
Quoted 2 lines · Rubén Justo
Plug a leak we have since
cfb6f9acc3(apply: accept -3/--3way command line option, 2012-05-08).Looking at that commit I see
(quoted diff) +5
-2- if (apply_fragments(&image, patch) < 0) - return -1; /* note with --reject this succeeds. */ + if (apply_fragments(&image, patch) < 0) { + /* Note: with --reject, apply_fragments() returns 0 */ + if (!threeway || try_threeway(&image, patch, st, ce) < 0) + return -1; + }
Quoted 6 lines
So the leak existed before that commit. Indeed it looks like the leak predates the introduction of struct image in
b94f2eda99(builtin-apply.c: make it more line oriented, 2008-01-26) and when the patch does not apply we have been leaking the buffer passed toapply_fragments()since the beginning of the builtin apply added inac6245e31a3(Builtin git-apply., 2006-05-23)
You are very right.
I saw that commit. I reviewed again my notes and I recorded the hash of the previous hop; the one that my message, incorrectly, refers to. I'll reroll to fix it.
Thank you very much for your attention.
Re: [PATCH 1/4] apply: plug a leak in apply_data
Quoted 7 lines · Rubén Justo
Quoted 6 lines
So the leak existed before that commit. Indeed it looks like the leak predates the introduction of struct image in
b94f2eda99(builtin-apply.c: make it more line oriented, 2008-01-26) and when the patch does not apply we have been leaking the buffer passed toapply_fragments()since the beginning of the builtin apply added inac6245e31a3(Builtin git-apply., 2006-05-23)
Quoted 5 lines
You are very right.
I saw that commit. I reviewed again my notes and I recorded the hash of the previous hop; the one that my message, incorrectly, refers to. I'll reroll to fix it.
FWIW, the very first version of apply_one_fragment() in 3cca928d (git-apply: first cut at actually checking fragment data, 2005-06-05) already had leak; it "returns -1" upon an error without freeing old/new buffers. Over the years, the shape of the code changed, but the leak survived.
PATCH 2/4 add-interactive: plug a leak in get_untracked_files
In reply to Rubén JustoPlug a leak we have since ab1e1cccaf (built-in add -i: re-implement add-untracked in C, 2019-11-29).
This leak can be triggered with:
$ echo a | git add -i
As a curiosity, we have a somewhat similar function in builtin/stash.c, which correctly frees the memory.
--- add-interactive.c | 1 + 1 file changed, 1 insertion(+)
add-interactive.c +1 -0
@@ -865,6 +865,7 @@ static int get_untracked_files(struct repository *r, }strbuf_release (&buf); +dir_clear (&dir);return 0 ; }
Signature · 1 line
2.45.0.rc0.4.g08f77eb516
Re: [PATCH 2/4] add-interactive: plug a leak in get_untracked_files
Quoted 9 lines · Rubén Justo
Plug a leak we have since
ab1e1cccaf(built-in add -i: re-implementadd-untrackedin C, 2019-11-29).This leak can be triggered with:
$ echo a | git add -iAs a curiosity, we have a somewhat similar function in
builtin/stash.c, which correctly frees the memory.
Yup,
$ git grep -W -e fill_directory -e dir_clear -e setup_standard_excludes \*.c
makes an interesting read ;-)
The fix looks good. Thanks.
Quoted 16 lines
Signed-off-by Rubén Justo <[email protected]>--- add-interactive.c | 1 + 1 file changed, 1 insertion(+)add-interactive.c +1
-0@@ -865,6 +865,7 @@ static int get_untracked_files(struct repository *r, }strbuf_release (&buf); +dir_clear (&dir);return 0 ; }
PATCH 3/4 add-patch: plug a leak handling the '/' command
In reply to Rubén JustoPlug a leak we have since d6cf873340 (built-in add -p: implement the '/' ("search regex") command, 2019-12-13).
This leak can be triggered with:
$ printf "A\n\nB\n" >file
$ git add file && git commit -m file
$ printf "AA\n\nBB\n" >file
$ printf "s\n/ .\n" >lines
$ git add -p <lines--- add-patch.c | 1 + 1 file changed, 1 insertion(+)
add-patch.c +1 -0
@@ -1646,6 +1646,7 @@ static int patch_update_file(struct add_p_state *s,err (s,_ ("No hunk matches the given pattern" ));break ; } +regfree (®ex); hunk_index = i; }else if (s->answer.buf[0 ] =='s' ) {size_t splittable_into = hunk->splittable_into;
Signature · 1 line
2.45.0.rc0.4.g08f77eb516
PATCH 4/4 add: plug a leak on interactive_add
In reply to Rubén JustoPlug a leak we have since 5a76aff1a6 (add: convert to use parse_pathspec, 2013-07-14).
This leak can be triggered with:
$ git add -p anything
Fixing this leak allows us to mark as leak-free the following tests:
+ t3701-add-interactive.sh
+ t7514-commit-patch.sh
Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
--- builtin/add.c | 9 ++++++--- t/t3701-add-interactive.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-)
builtin/add.c +6 -3
@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)int interactive_add (const char **argv,const char *prefix,int patch) {struct pathspec pathspec; -int unused; +int unused, ret;if (!git_config_get_bool ("add.interactive.usebuiltin" , &unused)) warning(_("the add.interactive.useBuiltin setting has been removed!\n"
@@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch) prefix, argv);if (patch) -return !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec); + ret = !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec);else -return !!run_add_i (the_repository, &pathspec); + ret = !!run_add_i (the_repository, &pathspec); + +clear_pathspec (&pathspec); +return ret; }static int edit_patch (int argc,const char **argv,const char *prefix)
t/t3701-add-interactive.sh +1 -0
@@ -4,6 +4,7 @@ test_description='add -i basic tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh
t/t7514-commit-patch.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='hunk edit with "commit -p -m"' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup (initial)' '
Signature · 1 line
2.45.0.rc0.4.g08f77eb516
Re: [PATCH 4/4] add: plug a leak on interactive_add
Hi Rubén
Quoted 6 lines · Rubén Justo
Plug a leak we have since
5a76aff1a6(add: convert to useparse_pathspec, 2013-07-14).This leak can be triggered with:
$ git add -p anything
Quoted 8 lines
Fixing this leak allows us to mark as leak-free the following tests:
+
t3701-add-interactive.sh
+t7514-commit-patch.shMark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
This makes me wonder if we're freeing the pathspec properly when using '--patch' in checkout, reset, restore and stash.
Best Wishes
Phillip
Quoted 60 lines
Signed-off-by Rubén Justo <[email protected]>--- builtin/add.c | 9 ++++++--- t/t3701-add-interactive.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-)builtin/add.c +6
-3@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)int interactive_add (const char **argv,const char *prefix,int patch) {struct pathspec pathspec; -int unused; +int unused, ret;if (!git_config_get_bool ("add.interactive.usebuiltin" , &unused)) warning(_("the add.interactive.useBuiltin setting has been removed!\n"@@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch) prefix, argv);if (patch) -return !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec); + ret = !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec);else -return !!run_add_i (the_repository, &pathspec); + ret = !!run_add_i (the_repository, &pathspec); + +clear_pathspec (&pathspec); +return ret; }static int edit_patch (int argc,const char **argv,const char *prefix)t/t3701-add-interactive.sh +1
-0@@ -4,6 +4,7 @@ test_description='add -i basic tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sht/t7514-commit-patch.sh +2
-0@@ -1,6 +1,8 @@ #!/bin/sh test_description='hunk edit with "commit -p -m"' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup (initial)' '
Re: [PATCH 4/4] add: plug a leak on interactive_add
Quoted 8 lines · Phillip Wood
Quoted 8 lines
Plug a leak we have since
5a76aff1a6(add: convert to useparse_pathspec, 2013-07-14).This leak can be triggered with:
$ git add -p anythingFixing this leak allows us to mark as leak-free the following tests:
Quoted 8 lines
Quoted 6 lines
+
t3701-add-interactive.sh
+t7514-commit-patch.shMark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
This makes me wonder if we're freeing the pathspec properly when using '--patch' in checkout, reset, restore and stash.
I haven't checked it thoroughly, but I think we're fine in those cases.
Quoted 5 lines · Rubén Justo
Rubén Justo (4):
apply: plug a leak inapply_data
add-interactive: plug a leak inget_untracked_files
add-patch: plug a leak handling the '/' command
add: plug a leak oninteractive_add
All of these patches look obviously good to me. Thanks!
Patrick
Quoted 5 lines · Rubén Justo
Rubén Justo (4):
apply: plug a leak inapply_data
add-interactive: plug a leak inget_untracked_files
add-patch: plug a leak handling the '/' command
add: plug a leak oninteractive_add
Thanks, will queue.
Quoted 16 lines
add-interactive.c | 1 + add-patch.c | 1 + apply.c | 4 +++- builtin/add.c | 9 ++++++--- t/t2016-checkout-patch.sh | 1 + t/t3701-add-interactive.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 14 files changed, 23 insertions(+), 4 deletions(-)
v2 cover mark t3701-add-interactive.sh as leak-free
In reply to Rubén JustoRubén Justo (4):
apply: plug a leak in apply_data
add-interactive: plug a leak in get_untracked_files
add-patch: plug a leak handling the '/' command
add: plug a leak on interactive_add
add-interactive.c | 1 + add-patch.c | 1 + apply.c | 4 +++- builtin/add.c | 9 ++++++--- t/t2016-checkout-patch.sh | 1 + t/t3701-add-interactive.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 14 files changed, 23 insertions(+), 4 deletions(-)
Range-diff against v1:
1: 18e4c7f653 ! 1: 75cb700eab apply: plug a leak in apply_data
@@ Metadata
## Commit message ##
apply: plug a leak in apply_data
- Plug a leak we have since cfb6f9acc3 (apply: accept -3/--3way command
- line option, 2012-05-08).
+ We have an execution path in apply_data that leaks the local struct
+ image. Plug it.
This leak can be triggered with:
2: 21d6c2dd16 = 2: bee002b0ae add-interactive: plug a leak in get_untracked_files 3: f69a6a30a1 = 3: 7d1a94dd91 add-patch: plug a leak handling the '/' command 4: 5d9607f153 = 4: fff7e48949 add: plug a leak on interactive_add
Signature · 1 line
2.45.0.rc0.4.gfff7e48949
PATCH v2 1/4 apply: plug a leak in apply_data
We have an execution path in apply_data that leaks the local struct image. Plug it.
This leak can be triggered with:
$ echo foo >file
$ git add file && git commit -m file
$ echo bar >file
$ git diff file >diff
$ sed s/foo/frotz/ <diff >baddiff
$ git apply --cached <baddiffFixing this leak allows us to mark as leak-free the following tests:
+ t2016-checkout-patch.sh
+ t4103-apply-binary.sh
+ t4104-apply-boundary.sh
+ t4113-apply-ending.sh
+ t4117-apply-reject.sh
+ t4123-apply-shrink.sh
+ t4252-am-options.sh
+ t4258-am-quoted-cr.sh
Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
--- apply.c | 4 +++- t/t2016-checkout-patch.sh | 1 + t/t4103-apply-binary.sh | 1 + t/t4104-apply-boundary.sh | 1 + t/t4113-apply-ending.sh | 1 + t/t4117-apply-reject.sh | 1 + t/t4123-apply-shrink.sh | 1 + t/t4252-am-options.sh | 2 ++ t/t4258-am-quoted-cr.sh | 1 + 9 files changed, 12 insertions(+), 1 deletion(-)
apply.c +3 -1
@@ -3712,8 +3712,10 @@ static int apply_data(struct apply_state *state, struct patch *patch,fprintf (stderr,_ ("Falling back to direct application...\n" ));/* Note: with --reject, apply_fragments() returns 0 */ -if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) +if (patch->direct_to_threeway ||apply_fragments (state, &image, patch) <0 ) { +clear_image (&image);return -1 ; + } } patch->result = image.buf; patch->resultsize = image.len;
t/t2016-checkout-patch.sh +1 -0
@@ -2,6 +2,7 @@ test_description='git checkout --patch' +TEST_PASSES_SANITIZE_LEAK=true . ./lib-patch-mode.sh test_expect_success 'setup' '
t/t4103-apply-binary.sh +1 -0
@@ -9,6 +9,7 @@ test_description='git apply handling binary patches GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' '
t/t4104-apply-boundary.sh +1 -0
@@ -5,6 +5,7 @@ test_description='git apply boundary tests' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh L="c d e f g h i j k l m n o p q r s t u v w x"
t/t4113-apply-ending.sh +1 -0
@@ -6,6 +6,7 @@ test_description='git apply trying to add an ending line. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # setup
t/t4117-apply-reject.sh +1 -0
@@ -7,6 +7,7 @@ test_description='git apply with rejects ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup '
t/t4123-apply-shrink.sh +1 -0
@@ -2,6 +2,7 @@ test_description='apply a patch that is larger than the preimage' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >F <<\EOF
t/t4252-am-options.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with options and not losing them' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh tm="$TEST_DIRECTORY/t4252"
t/t4258-am-quoted-cr.sh +1 -0
@@ -2,6 +2,7 @@ test_description='test am --quoted-cr=<action>' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh DATA="$TEST_DIRECTORY/t4258"
Signature · 1 line
2.45.0.rc0.4.gfff7e48949
PATCH v2 2/4 add-interactive: plug a leak in get_untracked_files
In reply to Rubén JustoPlug a leak we have since ab1e1cccaf (built-in add -i: re-implement add-untracked in C, 2019-11-29).
This leak can be triggered with:
$ echo a | git add -i
As a curiosity, we have a somewhat similar function in builtin/stash.c, which correctly frees the memory.
--- add-interactive.c | 1 + 1 file changed, 1 insertion(+)
add-interactive.c +1 -0
@@ -865,6 +865,7 @@ static int get_untracked_files(struct repository *r, }strbuf_release (&buf); +dir_clear (&dir);return 0 ; }
Signature · 1 line
2.45.0.rc0.4.gfff7e48949
PATCH v2 3/4 add-patch: plug a leak handling the '/' command
In reply to Rubén JustoPlug a leak we have since d6cf873340 (built-in add -p: implement the '/' ("search regex") command, 2019-12-13).
This leak can be triggered with:
$ printf "A\n\nB\n" >file
$ git add file && git commit -m file
$ printf "AA\n\nBB\n" >file
$ printf "s\n/ .\n" >lines
$ git add -p <lines--- add-patch.c | 1 + 1 file changed, 1 insertion(+)
add-patch.c +1 -0
@@ -1646,6 +1646,7 @@ static int patch_update_file(struct add_p_state *s,err (s,_ ("No hunk matches the given pattern" ));break ; } +regfree (®ex); hunk_index = i; }else if (s->answer.buf[0 ] =='s' ) {size_t splittable_into = hunk->splittable_into;
Signature · 1 line
2.45.0.rc0.4.gfff7e48949
PATCH v2 4/4 add: plug a leak on interactive_add
In reply to Rubén JustoPlug a leak we have since 5a76aff1a6 (add: convert to use parse_pathspec, 2013-07-14).
This leak can be triggered with:
$ git add -p anything
Fixing this leak allows us to mark as leak-free the following tests:
+ t3701-add-interactive.sh
+ t7514-commit-patch.sh
Mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promply any new leak that may be introduced and triggered by them in the future.
--- builtin/add.c | 9 ++++++--- t/t3701-add-interactive.sh | 1 + t/t7514-commit-patch.sh | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-)
builtin/add.c +6 -3
@@ -150,7 +150,7 @@ static int refresh(int verbose, const struct pathspec *pathspec)int interactive_add (const char **argv,const char *prefix,int patch) {struct pathspec pathspec; -int unused; +int unused, ret;if (!git_config_get_bool ("add.interactive.usebuiltin" , &unused)) warning(_("the add.interactive.useBuiltin setting has been removed!\n"
@@ -163,9 +163,12 @@ int interactive_add(const char **argv, const char *prefix, int patch) prefix, argv);if (patch) -return !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec); + ret = !!run_add_p (the_repository,ADD_P_ADD ,NULL , &pathspec);else -return !!run_add_i (the_repository, &pathspec); + ret = !!run_add_i (the_repository, &pathspec); + +clear_pathspec (&pathspec); +return ret; }static int edit_patch (int argc,const char **argv,const char *prefix)
t/t3701-add-interactive.sh +1 -0
@@ -4,6 +4,7 @@ test_description='add -i basic tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh
t/t7514-commit-patch.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='hunk edit with "commit -p -m"' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup (initial)' '
Signature · 1 line
2.45.0.rc0.4.gfff7e48949
Quoted 10 lines · Rubén Justo
Range-diff against v1:
1:18e4c7f653! 1:75cb700eabapply: plug a leak inapply_data
@@ Metadata
## Commit message ##
apply: plug a leak inapply_data- Plug a leak we have since
cfb6f9acc3(apply: accept -3/--3way command
- line option, 2012-05-08).
+ We have an execution path inapply_datathat leaks the local struct
+ image. Plug it.
This is a nice improvement.
If a bug existed in an ancient version and survived across evolution of the code for a long time, naming a random old version that happened to already have it does not help very much.
Saying something like
This is an ancient bug whose moral equivalent existed even before the data & code structure became the current shape in commit X
would give a bit more information, in that X gives a rough estimate how far back in the codebase the fix in the patch can be applied more or less cleanly. In this case, X would be where the struct image was introduced, I guess?
But the updated text is good enough and I do not see a need for reroll. Will queue. Thanks.