From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 7 18:40:22 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C5AD016A426 for ; Thu, 7 Jul 2005 18:40:22 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5446C43D70 for ; Thu, 7 Jul 2005 18:40:12 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j67IeBZH021082 for ; Thu, 7 Jul 2005 18:40:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j67IeBQx021079; Thu, 7 Jul 2005 18:40:11 GMT (envelope-from gnats) Resent-Date: Thu, 7 Jul 2005 18:40:11 GMT Resent-Message-Id: <200507071840.j67IeBQx021079@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Steve Sears Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 639CD16A41C for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: misc/83107: libc uuid_compare() doesn't work with large numbers X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2005 18:40:23 -0000 >Number: 83107 >Category: misc >Synopsis: libc uuid_compare() doesn't work with large numbers >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jul 07 18:40:11 GMT 2005 >Closed-Date: >Last-Modified: >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: >Unformatted: