From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11901 Path: news.gmane.org!.POSTED!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 2/2] free allocations in clearenv Date: Sun, 3 Sep 2017 22:12:21 +0300 Message-ID: <20170903191221.5287-3-amonakov@ispras.ru> References: <20170903191221.5287-1-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1504465994 30295 195.159.176.226 (3 Sep 2017 19:13:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Sep 2017 19:13:14 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11913-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 03 21:13:01 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1doaJy-0006HN-Fe for gllmg-musl@m.gmane.org; Sun, 03 Sep 2017 21:12:38 +0200 Original-Received: (qmail 31784 invoked by uid 550); 3 Sep 2017 19:12:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30644 invoked from network); 3 Sep 2017 19:12:33 -0000 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170903191221.5287-1-amonakov@ispras.ru> Xref: news.gmane.org gmane.linux.lib.musl.general:11901 Archived-At: This aligns clearenv with the Linux man page by setting 'environ' rather than '*environ' to NULL, and stops it from leaking entries allocated by the libc. --- src/env/clearenv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/env/clearenv.c b/src/env/clearenv.c index 62d50952..da187752 100644 --- a/src/env/clearenv.c +++ b/src/env/clearenv.c @@ -1,10 +1,14 @@ #define _GNU_SOURCE #include +#include "libc.h" -extern char **__environ; +static void dummy(char *old, char *new) {} +weak_alias(dummy, __env_rm_add); int clearenv() { - __environ[0] = 0; + char **e = __environ; + __environ = 0; + if (e) while (*e) __env_rm_add(*e++, 0); return 0; } -- 2.11.0