From 23677e98fe628331f7eb20a472bb7005f0ce7087 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Tue, 30 Sep 1997 18:08:11 +0000 Subject: [PATCH] Putting records with zero-length keys into a Berkeley DB hash database is asking for trouble (sequential database enumerations can get caught in an infinite loop). The yp_mkdb(8) utility avoids putting such records into a database, but ypxfr does not. Today I got bit by a NULL entry in one of the amd maps on my network, which is served by a SunOS master. The map was transfered successfully to my FreeBSD slave, but attempting to dump it with ypcat(1) caused ypserv(8) to transmit the same record over and over again, making the map appear to be infinitely large. I finally noticed the problem while testing a new version of amd under development at the Columbia CS department, which began gobbling up insane amounts of memory while trying to swallow the map. To deal with this problem, I'm modifying ypxfr to watch for records with zero-length keys and turn them into something less destructive before writing them to the database. --- libexec/ypxfr/ypxfr_main.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libexec/ypxfr/ypxfr_main.c b/libexec/ypxfr/ypxfr_main.c index 6e42c05ae93..1c905cca367 100644 --- a/libexec/ypxfr/ypxfr_main.c +++ b/libexec/ypxfr/ypxfr_main.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ypxfr_main.c,v 1.8 1997/02/22 14:22:48 peter Exp $ + * $Id: ypxfr_main.c,v 1.9 1997/03/28 15:48:21 imp Exp $ */ #include #include @@ -51,7 +51,7 @@ struct dom_binding {}; #include "ypxfr_extern.h" #ifndef lint -static const char rcsid[] = "$Id: ypxfr_main.c,v 1.8 1997/02/22 14:22:48 peter Exp $"; +static const char rcsid[] = "$Id: ypxfr_main.c,v 1.9 1997/03/28 15:48:21 imp Exp $"; #endif char *progname = "ypxfr"; @@ -133,10 +133,26 @@ int ypxfr_foreach(status, key, keylen, val, vallen, data) if (status != YP_TRUE) return (status); - dbkey.data = key; - dbkey.size = keylen; - dbval.data = val; - dbval.size = vallen; + /* + * XXX Do not attempt to write zero-length keys or + * data into a Berkeley DB hash database. It causes a + * strange failure mode where sequential searches get + * caught in an infinite loop. + */ + if (keylen) { + dbkey.data = key; + dbkey.size = keylen; + } else { + dbkey.data = ""; + dbkey.size = 1; + } + if (vallen) { + dbval.data = val; + dbval.size = vallen; + } else { + dbval.data = ""; + dbval.size = 1; + } if (yp_put_record(dbp, &dbkey, &dbval, 0) != YP_TRUE) return(yp_errno);