From nobody@FreeBSD.org  Thu Jul  7 18:33:44 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 639CD16A41C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Jul 2005 18:33:44 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0D9F343D48
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  7 Jul 2005 18:33:44 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j67IXfjv027700
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 7 Jul 2005 18:33:41 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j67IXfbl027699;
	Thu, 7 Jul 2005 18:33:41 GMT
	(envelope-from nobody)
Message-Id: <200507071833.j67IXfbl027699@www.freebsd.org>
Date: Thu, 7 Jul 2005 18:33:41 GMT
From: Steve Sears <sjs@acm.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: libc uuid_compare() doesn't work with large numbers
X-Send-Pr-Version: www-2.3

>Number:         83107
>Category:       kern
>Synopsis:       [libc] [patch] libc uuid_compare() doesn't work with large numbers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 07 18:40:11 GMT 2005
>Closed-Date:    Thu Apr 12 02:21:01 GMT 2007
>Last-Modified:  Thu Apr 12 02:30:02 GMT 2007
>Originator:     Steve Sears
>Release:        5.4
>Organization:
self
>Environment:
FreeBSD sjs-linux.nane.netapp.com 5.4-STABLE FreeBSD 5.4-STABLE #19: Mon Apr 18 11:28:21 EDT 2005     root@sjs-linux.nane.netapp.com:/usr/src/sys-sjs/i386/compile/SJSKERN  i386

>Description:
      If you use uuid_compare and the uuid's are very different, an int
is too small to contain the results. For example, according to this code:

865e1a56-b9d9-11d9-ba27-0003476f2e88 < 062ac45c-b9d9-11d9-ba27-0003476f2e88

The implementation takes the results of a subtraction of the numbers
and assigns it to an int. But if the high bits remain on after the
subtraction, an int is too small and the results are negative.

The routine is located at ./src/lib/libc/uuid/uuid_compare.c

>How-To-Repeat:
      Invoke uuid_compare with the above two numbers. 

>Fix:
      Very simple fix: in uuid_compare.c, uuid_compare(), change the
local variable 'res' from int to int64_t. Remove the '(int)' cast from
the first subtraction.

Cdiff follows:

=== /u/sjs/freebsd/usr/src/lib/libc/uuid/uuid_compare.c ====
***************
*** 41,47 ****
  int32_t
  uuid_compare(uuid_t *a, uuid_t *b, uint32_t *status)
  {
!       int res;
  
        if (status != NULL)
                *status = uuid_s_ok;
--- 41,47 ----
  int32_t
  uuid_compare(uuid_t *a, uuid_t *b, uint32_t *status)
  {
!       int64_t res;
  
        if (status != NULL)
                *status = uuid_s_ok;
***************
*** 55,61 ****
                return ((uuid_is_nil(a, NULL)) ? 0 : 1);
  
        /* We have to compare the hard way. */
!       res = (int)((int64_t)a->time_low - (int64_t)b->time_low);
        if (res)
                return ((res < 0) ? -1 : 1);
        res = (int)a->time_mid - (int)b->time_mid;
--- 55,61 ----
                return ((uuid_is_nil(a, NULL)) ? 0 : 1);
  
        /* We have to compare the hard way. */
!       res = (int64_t)a->time_low - (int64_t)b->time_low;
        if (res)
                return ((res < 0) ? -1 : 1);
        res = (int)a->time_mid - (int)b->time_mid;

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Wed Jul 13 04:58:55 GMT 2005 
Responsible-Changed-Why:  
Grab 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83107 
Responsible-Changed-From-To: delphij->freebsd-bugs 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Mon Jan 23 13:30:23 UTC 2006 
Responsible-Changed-Why:  
Return this back to pool due to lack of time. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83107 
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Thu Aug 3 03:34:26 UTC 2006 
State-Changed-Why:  
A slightly different patch applied against -HEAD. 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Thu Aug 3 03:34:26 UTC 2006 
Responsible-Changed-Why:  
MFC Reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83107 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/83107: commit references a PR
Date: Thu, 12 Apr 2007 02:19:22 +0000 (UTC)

 delphij     2007-04-12 02:19:17 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     lib/libc/uuid        uuid_compare.c 
   Log:
   MFC 1.5-1.6: Correctly compare between two UUIDs according
   to specification found DCE 1.1.
   
   PR:             83107
   
   Revision  Changes    Path
   1.4.2.1   +15 -17    src/lib/libc/uuid/uuid_compare.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Thu Apr 12 02:20:33 UTC 2007 
State-Changed-Why:  
Patch applied against RELENG_6.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=83107 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/83107: commit references a PR
Date: Thu, 12 Apr 2007 02:20:21 +0000 (UTC)

 delphij     2007-04-12 02:20:15 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_5)
     lib/libc/uuid        uuid_compare.c 
   Log:
   MFC 1.5-1.6: Correctly compare between two UUIDs according
   to specification found DCE 1.1.
   
   PR:             83107
   
   Revision  Changes    Path
   1.3.4.1   +15 -17    src/lib/libc/uuid/uuid_compare.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
