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.
This commit is contained in:
Bill Paul 1997-09-30 18:08:11 +00:00
parent 026650e576
commit 23677e98fe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=30008

View File

@ -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 <stdio.h>
#include <stdlib.h>
@ -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);