1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-03 01:18:10 +03:00

util:datablob: avoid non-transitive comparison in data_blob_cmp()

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>
(cherry picked from commit e1519c3667)
This commit is contained in:
Douglas Bagnall 2024-04-04 11:07:06 +13:00 committed by Jule Anger
parent f7e192e82f
commit 7990f5a284

View File

@ -22,6 +22,7 @@
#include "attr.h" #include "attr.h"
#include "data_blob.h" #include "data_blob.h"
#include "lib/util/samba_util.h" #include "lib/util/samba_util.h"
#include "lib/util/tsort.h"
const DATA_BLOB data_blob_null = { NULL, 0 }; const DATA_BLOB data_blob_null = { NULL, 0 };
@ -121,12 +122,12 @@ _PUBLIC_ int data_blob_cmp(const DATA_BLOB *d1, const DATA_BLOB *d2)
return 1; return 1;
} }
if (d1->data == d2->data) { if (d1->data == d2->data) {
return d1->length - d2->length; return NUMERIC_CMP(d1->length, d2->length);
} }
ret = memcmp(d1->data, d2->data, MIN(d1->length, d2->length)); ret = memcmp(d1->data, d2->data, MIN(d1->length, d2->length));
if (ret == 0) { if (ret == 0) {
/* Note this ordering is used in conditional aces */ /* Note this ordering is used in conditional aces */
return d1->length - d2->length; return NUMERIC_CMP(d1->length, d2->length);
} }
return ret; return ret;
} }