summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/tsearch.c
diff options
context:
space:
mode:
authormoritz <moritz@openbsd.org>2006-04-04 11:21:50 +0000
committermoritz <moritz@openbsd.org>2006-04-04 11:21:50 +0000
commit2e6f60c16b348ead623d2047a563b9451e8fbf56 (patch)
tree7ae045a1d97f12b8d018d56bb1fde400b41060a8 /lib/libc/stdlib/tsearch.c
parentFix a comment (diff)
downloadwireguard-openbsd-2e6f60c16b348ead623d2047a563b9451e8fbf56.tar.xz
wireguard-openbsd-2e6f60c16b348ead623d2047a563b9451e8fbf56.zip
When tdelete() is used to delete the root node, don't return a
pointer to the freed root node, but return a pointer to the new root node. POSIX does not define, what should be returned in that case. Fixes Coverity CID 2528. ok millert@ otto@
Diffstat (limited to 'lib/libc/stdlib/tsearch.c')
-rw-r--r--lib/libc/stdlib/tsearch.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/libc/stdlib/tsearch.c b/lib/libc/stdlib/tsearch.c
index a5d0c2b9b3d..667c57731bb 100644
--- a/lib/libc/stdlib/tsearch.c
+++ b/lib/libc/stdlib/tsearch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tsearch.c,v 1.5 2005/03/30 18:51:49 pat Exp $ */
+/* $OpenBSD: tsearch.c,v 1.6 2006/04/04 11:21:50 moritz Exp $ */
/*
* Tree search generalized from Knuth (6.2.2) Algorithm T just like
@@ -86,6 +86,8 @@ tdelete(const void *vkey, void **vrootp,
q->right = (*rootp)->right;
}
}
+ if (p == *rootp)
+ p = q;
free((struct node_t *) *rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */
return(p);