From a106fefcfb0cb60ce439884d8cd0c920d2fb193a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 20 Dec 2009 10:25:46 +1100 Subject: librpc: fixed the GUID_compare() function When comparing two unsigned values you can't just subtract them. Imagine you are comparing: "uint32_t u1" and "uint32_t u2". If you use "u1 - u2" and u2 is zero, then the signed integer result will depend on the top bit of u1. This error occurs in a few places in Samba. For DRS replication it resulted in corrupt uptodateness vectors. --- librpc/ndr/uuid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'librpc/ndr') diff --git a/librpc/ndr/uuid.c b/librpc/ndr/uuid.c index 429a1b1ac9..1899afbbca 100644 --- a/librpc/ndr/uuid.c +++ b/librpc/ndr/uuid.c @@ -241,23 +241,23 @@ _PUBLIC_ bool GUID_equal(const struct GUID *u1, const struct GUID *u2) _PUBLIC_ int GUID_compare(const struct GUID *u1, const struct GUID *u2) { if (u1->time_low != u2->time_low) { - return u1->time_low - u2->time_low; + return u1->time_low > u2->time_low ? 1 : -1; } if (u1->time_mid != u2->time_mid) { - return u1->time_mid - u2->time_mid; + return u1->time_mid > u2->time_mid ? 1 : -1; } if (u1->time_hi_and_version != u2->time_hi_and_version) { - return u1->time_hi_and_version - u2->time_hi_and_version; + return u1->time_hi_and_version > u2->time_hi_and_version ? 1 : -1; } if (u1->clock_seq[0] != u2->clock_seq[0]) { - return u1->clock_seq[0] - u2->clock_seq[0]; + return u1->clock_seq[0] > u2->clock_seq[0] ? 1 : -1; } if (u1->clock_seq[1] != u2->clock_seq[1]) { - return u1->clock_seq[1] - u2->clock_seq[1]; + return u1->clock_seq[1] > u2->clock_seq[1] ? 1 : -1; } return memcmp(u1->node, u2->node, 6); -- cgit