diff options
author | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-01-14 16:39:22 +0000 |
---|---|---|
committer | Jean-Francois Brousseau <jfb@cvs.openbsd.org> | 2005-01-14 16:39:22 +0000 |
commit | 79f835d30a8a64ebb3144136f34457e0b1aee8d0 (patch) | |
tree | 3bcc7232cfad23e446717ab9d1d9d52832bef34d /usr.bin | |
parent | c701ddbb28f0bb41673c135f6cfe5280e7f341a3 (diff) |
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')
-rw-r--r-- | usr.bin/cvs/entries.c | 12 |
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); |