NetBSD Problem Report #53371

From www@NetBSD.org  Sat Jun 16 11:37:52 2018
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 2B6C07A152
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 16 Jun 2018 11:37:52 +0000 (UTC)
Message-Id: <20180616113751.110747A271@mollari.NetBSD.org>
Date: Sat, 16 Jun 2018 11:37:51 +0000 (UTC)
From: thomas.barabosch@fkie.fraunhofer.de
Reply-To: thomas.barabosch@fkie.fraunhofer.de
To: gnats-bugs@NetBSD.org
Subject: Potential memory leak in usr.sbin/ndp/ndp.c
X-Send-Pr-Version: www-1.0

>Number:         53371
>Category:       bin
>Synopsis:       Potential memory leak in usr.sbin/ndp/ndp.c
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 16 11:40:00 +0000 2018
>Closed-Date:    Sat Jun 16 20:31:21 +0000 2018
>Last-Modified:  Sat Jun 16 20:31:21 +0000 2018
>Originator:     Thomas Barabosch
>Release:        7.1.2
>Organization:
Fraunhofer FKIE
>Environment:
>Description:
According to getaddrinfo.3, we must deallocate the data received by getaddrinfo with freeaddrinfo. However, this is no done in ndp.c. There are three calls to getaddrinfo, but none to freeaddrinfo. Hence, we are leaking memory, though this should not be that critical in this case. Nevertheless, to use the libraries calls correctly, I've drafted a patch to add the missing calls. I've added the calls as soon as possible, I hope that is OK this way. Alternatively, we could free the memory at the very end of the corresponding functions...
>How-To-Repeat:

>Fix:
--- usr.sbin/ndp/ndp.c	2018-05-14 00:00:49.708718130 +0200
+++ usr.sbin/ndp/ndp.c.patched	2018-06-16 13:33:04.183277142 +0200
@@ -376,6 +376,7 @@
 		return 1;
 	}
 	makeaddr(mysin, res->ai_addr);
+	freeaddrinfo(res);
 	ea = (u_char *)LLADDR(&sdl_m);
 	if (ndp_ether_aton(eaddr, ea) == 0)
 		sdl_m.sdl_alen = 6;
@@ -441,6 +442,7 @@
 		return;
 	}
 	makeaddr(mysin, res->ai_addr);
+	freeaddrinfo(res);
 	do_foreach(&mysin->sin6_addr, host, 0);
 	if (found_entry == 0) {
 		(void)getnameinfo((struct sockaddr *)(void *)mysin,
@@ -467,6 +469,7 @@
 		return;
 	}
 	makeaddr(mysin, res->ai_addr);
+	freeaddrinfo(res);
 	do_foreach(&mysin->sin6_addr, host, NDP_F_DELETE);
 }


>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53371 CVS commit: src/usr.sbin/ndp
Date: Sat, 16 Jun 2018 09:09:41 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sat Jun 16 13:09:41 UTC 2018

 Modified Files:
 	src/usr.sbin/ndp: ndp.c

 Log Message:
 PR/53371: Thomas Barabosch: Potential memory leak in usr.sbin/ndp/ndp.c


 To generate a diff of this commit:
 cvs rdiff -u -r1.50 -r1.51 src/usr.sbin/ndp/ndp.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Sat, 16 Jun 2018 20:31:21 +0000
State-Changed-Why:
Fixed by christos, thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.