mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
vim-patch:9.1.0089: qsort() comparison functions should be transitive
Problem: qsort() comparison functions should be transitive
Solution: Do not subtract values, but rather use explicit comparisons
Improve qsort() comparison functions
There has been a recent report on qsort() causing out-of-bounds read &
write in glibc for non transitive comparison functions
https://www.qualys.com/2024/01/30/qsort.txt
Even so the bug is in glibc's implementation of the qsort() algorithm,
it's bad style to just use substraction for the comparison functions,
which may cause overflow issues and as hinted at in OpenBSD's manual
page for qsort(): "It is almost always an error to use subtraction to
compute the return value of the comparison function."
So check the qsort() comparison functions and change them to be safe.
closes: vim/vim#13980
e06e437665
Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
@@ -7359,9 +7359,17 @@ static bool frame_check_width(const frame_T *topfrp, int width)
|
||||
}
|
||||
|
||||
/// Simple int comparison function for use with qsort()
|
||||
static int int_cmp(const void *a, const void *b)
|
||||
static int int_cmp(const void *pa, const void *pb)
|
||||
{
|
||||
return *(const int *)a - *(const int *)b;
|
||||
const int a = *(const int *)pa;
|
||||
const int b = *(const int *)pb;
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
||||
|
Reference in New Issue
Block a user