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
merge-ort: only do pointer arithmetic for non-empty lists #930
Conversation
/preview |
Preview email sent as pull.930.git.1618040584669.gitgitgadget@gmail.com |
/preview |
Preview email sent as pull.930.git.1618043083141.gitgitgadget@gmail.com |
/submit |
Submitted as pull.930.git.1618043449249.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, René Scharfe wrote (reply to this):
|
User |
On the Git mailing list, Junio C Hamano wrote (reply to this):
|
/preview |
Preview email sent as pull.930.v2.git.1618132269021.gitgitgadget@gmail.com |
On the Git mailing list, Andrzej Hunt wrote (reply to this):
|
On the Git mailing list, Andrzej Hunt wrote (reply to this):
|
/preview |
Preview email sent as pull.930.v2.git.1618132763405.gitgitgadget@gmail.com |
cb3bb7e
to
e702e69
Compare
versions could be an empty string_list. In that case, versions->items is NULL, and we shouldn't be trying to perform pointer arithmetic with it (as that results in undefined behaviour). Moreover we only use the results of this calculation once when calling QSORT. Therefore we choose to skip creating relevant_entries and call QSORT directly with our manipulated pointers (but only if there's data requiring sorting). This lets us avoid abusing the string_list API, and saves us from having to explain why this abuse is OK. Finally, an assertion is added to make sure that write_tree() is called with a valid offset. This issue has probably existed since: ee4012d (merge-ort: step 2 of tree writing -- function to create tree object, 2020-12-13) But it only started occurring during tests since tests started using merge-ort: f3b964a (Add testing with merge-ort merge strategy, 2021-03-20) For reference - here's the original UBSAN commit that implemented this check, it sounds like this behaviour isn't actually likely to cause any issues (but we might as well fix it regardless): https://reviews.llvm.org/D67122 UBSAN output from t3404 or t5601: merge-ort.c:2669:43: runtime error: applying zero offset to null pointer #0 0x78bb53 in write_tree merge-ort.c:2669:43 #1 0x7856c9 in process_entries merge-ort.c:3303:2 #2 0x782317 in merge_ort_nonrecursive_internal merge-ort.c:3744:2 #3 0x77feef in merge_incore_nonrecursive merge-ort.c:3853:2 #4 0x6f6a5c in do_recursive_merge sequencer.c:640:3 #5 0x6f6a5c in do_pick_commit sequencer.c:2221:9 #6 0x6ef055 in single_pick sequencer.c:4814:9 #7 0x6ef055 in sequencer_pick_revisions sequencer.c:4867:10 git#8 0x4fb392 in run_sequencer revert.c:225:9 git#9 0x4fa5b0 in cmd_revert revert.c:235:8 git#10 0x42abd7 in run_builtin git.c:453:11 git#11 0x429531 in handle_builtin git.c:704:3 git#12 0x4282fb in run_argv git.c:771:4 git#13 0x4282fb in cmd_main git.c:902:19 git#14 0x524b63 in main common-main.c:52:11 git#15 0x7fc2ca340349 in __libc_start_main (/lib64/libc.so.6+0x24349) git#16 0x4072b9 in _start start.S:120 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior merge-ort.c:2669:43 in Signed-off-by: Andrzej Hunt <ajrhunt@google.com>
/submit |
Submitted as pull.930.v2.git.1618139107203.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Elijah Newren wrote (reply to this):
|
On the Git mailing list, Junio C Hamano wrote (reply to this):
|
On the Git mailing list, Junio C Hamano wrote (reply to this):
|
This branch is now known as |
This patch series was integrated into seen via git@8a64e23. |
There was a status update in the "New Topics" section about the branch Code clean-up for merge-ort backend. Will merge to 'next'? |
This patch series was integrated into seen via git@8849ece. |
This patch series was integrated into next via git@41713a3. |
This patch series was integrated into seen via git@d53f509. |
There was a status update in the "Cooking" section about the branch Code clean-up for merge-ort backend. Will merge to 'master'. |
This patch series was integrated into seen via git@257ae76. |
This patch series was integrated into next via git@257ae76. |
This patch series was integrated into master via git@257ae76. |
Closed via 257ae76. |
V2 removes relevant_entries as per René's suggestion, and adds an assertion as per Junio's question.
CC: Elijah Newren newren@gmail.com
cc: René Scharfe l.s.r@web.de