From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8961 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix tsearch, tfind, tdelete to handle null pointer input Date: Sat, 5 Dec 2015 21:53:59 +0100 Message-ID: <20151205205359.GX23362@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1449348862 3032 80.91.229.3 (5 Dec 2015 20:54:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 5 Dec 2015 20:54:22 +0000 (UTC) Cc: Ed Schouten To: musl@lists.openwall.com Original-X-From: musl-return-8974-gllmg-musl=m.gmane.org@lists.openwall.com Sat Dec 05 21:54:17 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1a5JqS-0000WA-8D for gllmg-musl@m.gmane.org; Sat, 05 Dec 2015 21:54:16 +0100 Original-Received: (qmail 27924 invoked by uid 550); 5 Dec 2015 20:54:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 27877 invoked from network); 5 Dec 2015 20:54:10 -0000 Mail-Followup-To: musl@lists.openwall.com, Ed Schouten Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Xref: news.gmane.org gmane.linux.lib.musl.general:8961 Archived-At: POSIX specifies the behaviour for null rootp input, but it was not implemented correctly. --- src/search/tsearch_avl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/search/tsearch_avl.c b/src/search/tsearch_avl.c index e4fb131..57194c8 100644 --- a/src/search/tsearch_avl.c +++ b/src/search/tsearch_avl.c @@ -151,6 +151,8 @@ static struct node *remove(struct node **n, const void *k, void *tdelete(const void *restrict key, void **restrict rootp, int(*compar)(const void *, const void *)) { + if (!rootp) + return 0; struct node *n = *rootp; struct node *ret; /* last argument is arbitrary non-null pointer @@ -163,6 +165,8 @@ void *tdelete(const void *restrict key, void **restrict rootp, void *tfind(const void *key, void *const *rootp, int(*compar)(const void *, const void *)) { + if (!rootp) + return 0; return find(*rootp, key, compar); } @@ -171,6 +175,8 @@ void *tsearch(const void *key, void **rootp, { struct node *update; struct node *ret; + if (!rootp) + return 0; update = insert(*rootp, key, compar, &ret); if (update) *rootp = update; -- 2.4.1