standards/55370: [patch] uuid_compare function (uuid(3))
incorrectly compares node fields.
Konstantin Oznobihin
bork at rsu.ru
Fri Aug 8 03:30:13 PDT 2003
>Number: 55370
>Category: standards
>Synopsis: [patch] uuid_compare function (uuid(3)) incorrectly compares node fields.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Aug 08 03:30:10 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Konstantin Oznobihin
>Release: FreeBSD 5.1-RELEASE i386
>Organization:
Computer Center of Rostov State University
>Environment:
System: FreeBSD mymachine.somewhere.ru 5.1-RELEASE FreeBSD 5.1-RELEASE #0: Tue Jul 29 15:00:26 MSD 2003 root at mymachine.somewhere.ru:/usr/src/sys/i386/compile/KERNEL i386
>Description:
When comparing two equal uuids with uuid_compare it returns -1,
while according to the DCE 1.1 RPC specification it should be 0.
By checking the source I found this code
(see src/lib/libc/uuid/uuid_compare.c line 75):
memcmp(a->node, b->node, sizeof(uuid_t))
where a and b are of type uuid_t* and the node field of the struct uuid
is declared as
uint8_t node[_UUID_NODE_LEN]
so the size of uuid_t is always greater than size of node.
>How-To-Repeat:
Compile following program and run:
#include <sys/cdefs.h>
#include <stdio.h>
#include <uuid.h>
int
main()
{
uuid_t uuid1, uuid2;
int32_t ret;
const char *uuid_str =
"d95bc5d4-c97c-11d7-ba3d-112233445566";
uuid_from_string(uuid_str, &uuid1, NULL);
uuid_from_string(uuid_str, &uuid2, NULL);
ret = uuid_compare(&uuid1, &uuid2, NULL);
printf("compare ret: %d\n", ret);
ret = uuid_equal(&uuid1, &uuid2, NULL);
printf("equal ret: %d\n", ret);
return 0;
}
>Fix:
Fix the /usr/src/lib/libc/uuid/uuid_compare.c
--- uuid_compare.patch begins here ---
--- uuid_compare.c Fri Aug 8 13:31:20 2003
+++ /usr/src/lib/libc/uuid/uuid_compare.c Wed Oct 30 06:51:00 2002
@@ -72,5 +72,5 @@
res = (int)a->clock_seq_low - (int)b->clock_seq_low;
if (res)
return ((res < 0) ? -1 : 1);
- return (memcmp(a->node, b->node, _UUID_NODE_LEN));
+ return (memcmp(a->node, b->node, sizeof(uuid_t)));
}
--- uuid_compare.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list