summaryrefslogtreecommitdiffstats
path: root/usr.bin/cvs/entries.c
diff options
context:
space:
mode:
authorjfb <jfb@openbsd.org>2005-01-14 16:39:21 +0000
committerjfb <jfb@openbsd.org>2005-01-14 16:39:21 +0000
commit683ea36bae150bb97de31201db5e6eb7105526ce (patch)
tree908793692cd817165f4211d73571f2856c567299 /usr.bin/cvs/entries.c
parentMinor KNF and tweaks, also interrupt at IPL_TTY rather than IPL_BIO. (diff)
downloadwireguard-openbsd-683ea36bae150bb97de31201db5e6eb7105526ce.tar.xz
wireguard-openbsd-683ea36bae150bb97de31201db5e6eb7105526ce.zip
when removing the last entry from the tail queue, reinitialize the
queue for sanity, and make sure that the current pointer is set to the next item if it points to the item being removed. fixes a crash reported by brad@, tested by joris and brad@
Diffstat (limited to 'usr.bin/cvs/entries.c')
-rw-r--r--usr.bin/cvs/entries.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c
index 82315e71610..167ddaf6ff4 100644
--- a/usr.bin/cvs/entries.c
+++ b/usr.bin/cvs/entries.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entries.c,v 1.21 2004/12/14 21:23:44 jfb Exp $ */
+/* $OpenBSD: entries.c,v 1.22 2005/01/14 16:39:21 jfb Exp $ */
/*
* Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -246,9 +246,19 @@ cvs_ent_remove(CVSENTRIES *ef, const char *name)
if (ent == NULL)
return (-1);
+ if (ef->cef_cur == ent) {
+ /* if this element was the last one retrieved through a
+ * call to cvs_ent_next(), point to the next element to avoid
+ * keeping an invalid reference.
+ */
+ ef->cef_cur = TAILQ_NEXT(ef->cef_cur, ce_list);
+ }
TAILQ_REMOVE(&(ef->cef_ent), ent, ce_list);
cvs_ent_free(ent);
+ if (TAILQ_EMPTY(&(ef->cef_ent))) /* reset */
+ TAILQ_INIT(&(ef->cef_ent));
+
ef->cef_flags &= ~CVS_ENTF_SYNC;
return (0);