NetBSD Problem Report #41564

From www@NetBSD.org  Tue Jun  9 18:40:42 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 2F65163BF62
	for <gnats-bugs@gnats.netbsd.org>; Tue,  9 Jun 2009 18:40:42 +0000 (UTC)
Message-Id: <20090609184041.E384363B9E6@www.NetBSD.org>
Date: Tue,  9 Jun 2009 18:40:41 +0000 (UTC)
From: ekamperi@gmail.com
Reply-To: ekamperi@gmail.com
To: gnats-bugs@NetBSD.org
Subject: hdestroy(3) restricts ENTRY.key to point to malloc'ed space.
X-Send-Pr-Version: www-1.0

>Number:         41564
>Category:       lib
>Synopsis:       hdestroy(3) restricts ENTRY.key to point to malloc'ed space.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 09 18:45:00 +0000 2009
>Originator:     Stathis Kamperis
>Release:        NetBSD 5.0_STABLE
>Organization:
Aristotle University of Thessaloniki
>Environment:
NetBSD voyager 5.0_STABLE NetBSD 5.0_STABLE (MYGENERIC) #4: Sat May 23 15:45:44 EEST 2009  root@voyager:/usr/obj/sys/arch/i386/compile/MYGENERIC i386
>Description:
hdestroy(3) frees the memory pointed to by ENTRY.key. In other words it expects the user to have malloc'ed rather than used static allocation. This refers only to ENTRY.key and not to ENTRY.data.

Although the POSIX standard doesn't say anything on this particular topic:

1) This is unnecessarily restrictive.  If the user wants static allocation fine; if she wants dynamic then let *her* free the memory she malloc'ed.

2) It is in conflict with the example code in the POSIX page (the code segfaults).

3) Programs that target other implementations may segfault (that's how I discovered it). AFAIK sunOS 5.10 and a recent glibc work fine, whereas {Net, Free, DragonFly}BSD all are affected.
>How-To-Repeat:
Try to call hdestroy() in the example code of:
http://www.opengroup.org/onlinepubs/009695399/functions/hcreate.html

>Fix:
Just remove the following line from hdestroy():
		free(ie->ent.key);

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.