Skip to content

Commit 4b6ae60

Browse files
committed
fr_value_box_cmp() is used in stable sorts
and therefore can't call fr_digest_cmp().
1 parent 99d89e6 commit 4b6ae60

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

src/lib/util/value.c

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -758,41 +758,12 @@ int8_t fr_value_box_cmp(fr_value_box_t const *a, fr_value_box_t const *b)
758758
*/
759759
switch (a->type) {
760760
case FR_TYPE_VARIABLE_SIZE:
761-
{
762-
size_t length;
763-
764-
if (a->vb_length < b->vb_length) {
765-
length = a->vb_length;
766-
} else {
767-
length = b->vb_length;
768-
}
769-
770-
if (length) {
771-
int cmp;
772-
773-
/*
774-
* Use constant-time comparisons for secret values.
775-
*
776-
* @todo - this can leak data about the length of the secret, as the comparison
777-
* is done only up to the length of the shortest input. In order to fix this, we
778-
* would have to do a lot more work. For now, this is good enough.
779-
*/
780-
if (a->secret || b->secret) {
781-
cmp = fr_digest_cmp(a->datum.ptr, b->datum.ptr, length);
782-
} else {
783-
cmp = memcmp(a->datum.ptr, b->datum.ptr, length);
784-
}
785-
if (cmp != 0) return CMP(cmp, 0);
786-
}
787-
788761
/*
789-
* Contents are the same. The return code
790-
* is therefore the difference in lengths.
791-
*
792-
* i.e. "0x00" is smaller than "0x0000"
762+
* Note that we do NOT check a->secret or b->secret. This function is used to sort pairs
763+
* and sets of value-boxes. The fr_digest_cmp() function returns 0..255 no matter what
764+
* the two inputs are. So it can't be used in a stable sort.
793765
*/
794-
return CMP(a->vb_length, b->vb_length);
795-
}
766+
return MEMCMP_FIELDS(a, b, datum.ptr, vb_length);
796767

797768
/*
798769
* Short-hand for simplicity.

0 commit comments

Comments
 (0)