From owner-freebsd-bugs Tue Nov 3 16:30:03 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA13832 for freebsd-bugs-outgoing; Tue, 3 Nov 1998 16:30:03 -0800 (PST) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA13773 for ; Tue, 3 Nov 1998 16:30:00 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id QAA17144; Tue, 3 Nov 1998 16:30:01 -0800 (PST) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA12942 for ; Tue, 3 Nov 1998 16:23:27 -0800 (PST) (envelope-from archie@whistle.com) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id QAA19252 for ; Tue, 3 Nov 1998 16:23:15 -0800 (PST) Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3) id sma019248; Tue Nov 3 16:22:58 1998 Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id QAA16848; Tue, 3 Nov 1998 16:22:57 -0800 (PST) Message-Id: <199811040022.QAA16848@bubba.whistle.com> Date: Tue, 3 Nov 1998 16:22:57 -0800 (PST) From: Archie Cobbs Reply-To: archie@whistle.com To: FreeBSD-gnats-submit@FreeBSD.ORG X-Send-Pr-Version: 3.2 Subject: bin/8566: mergesort() core dumps if number of elements is zero Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 8566 >Category: bin >Synopsis: mergesort() core dumps if number of elements is zero >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Nov 3 16:30:01 PST 1998 >Last-Modified: >Originator: Archie Cobbs >Organization: Whistle Communications, Inc. >Release: FreeBSD 2.2.6-RELEASE i386 >Environment: FreeBSD 2.2-stable AND 3.0-current >Description: If meregsort() is called with number of elements == 0, it will still try to compare them (!), causing a core dump or worse. >How-To-Repeat: Compile and run this program: #include #include static int compare(const void *v1, const void *v2) { return(*((int *) v1) - *((int *) v2)); } int main(void) { int *array = NULL; if (mergesort(array, 0, 4, compare) < 0) err(1, "mergesort"); } >Fix: NOTE: Please fix this in BOTH 2.2 and 3.0.. thanks! Index: merge.c =================================================================== RCS file: /cvs/freebsd/src/lib/libc/stdlib/merge.c,v retrieving revision 1.2 diff -u -r1.2 merge.c --- merge.c 1995/05/30 05:41:50 1.2 +++ merge.c 1998/11/04 00:19:56 @@ -111,6 +111,9 @@ return (-1); } + if (nmemb == 0) + return (0); + /* * XXX * Stupid subtraction for the Cray. >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message