Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-05-20 09:09:37 +0300
committerJunio C Hamano <gitster@pobox.com>2021-05-20 09:40:39 +0300
commit19ceb486f8dd25fb5782724c454edb2f06f1ed71 (patch)
treee4835554d8aa3e980aa56ea4f0e4b01901b6d32c /merge-ort.h
parent64aceb6d738394130a6e215dc6de51d8452313e0 (diff)
merge-ort: avoid accidental API mis-use
Previously, callers of the merge-ort API could have passed an uninitialized value for struct merge_result *result. However, we want to check result to see if it has cached renames from a previous merge that we can reuse; such values would be found behind result->priv. However, if result->priv is uninitialized, attempting to access behind it will give a segfault. So, we need result->priv to be NULL (which will be the case if the caller does a memset(&result, 0)), or be written by a previous call to the merge-ort machinery. Documenting this requirement may help, but despite being the person who introduced this requirement, I still missed it once and it did not fail in a very clear way and led to a long debugging session. Add a _properly_initialized field to merge_result; that value will be 0 if the caller zero'ed the merge_result, it will be set to a very specific value by a previous run by the merge-ort machinery, and if it's uninitialized it will most likely either be 0 or some value that does not match the specific one we'd expect allowing us to throw a much more meaningful error. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-ort.h')
-rw-r--r--merge-ort.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/merge-ort.h b/merge-ort.h
index d53a0a339f..c011864ffe 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -29,6 +29,8 @@ struct merge_result {
* !clean) and to print "CONFLICT" messages. Not for external use.
*/
void *priv;
+ /* Also private */
+ unsigned _properly_initialized;
};
/*