1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ldb:sort: check that elements have values

We assume no values is unlikely, since we have been dereferencing
->values[0] forever, with no known reports of trouble.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15625

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2024-04-07 14:55:27 +12:00 committed by Andrew Bartlett
parent d785c1991c
commit d4e69734c6

View File

@ -122,7 +122,8 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo
el2 = ldb_msg_find_element(*msg2, ac->attributeName);
/*
* NULL elements sort at the end (regardless of ac->reverse flag).
* NULL and empty elements sort at the end (regardless of ac->reverse flag).
* NULL elements come after empty ones.
*/
if (el1 == NULL && el2 == NULL) {
return 0;
@ -133,6 +134,15 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo
if (el2 == NULL) {
return -1;
}
if (unlikely(el1->num_values == 0 && el2->num_values == 0)) {
return 0;
}
if (unlikely(el1->num_values == 0)) {
return 1;
}
if (unlikely(el2->num_values == 0)) {
return -1;
}
if (ac->reverse)
return ac->a->syntax->comparison_fn(ldb, ac, &el2->values[0], &el1->values[0]);