summaryrefslogtreecommitdiffstats
path: root/libexec/ypxfr
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1997-09-30 18:08:11 +0000
committerwpaul <wpaul@FreeBSD.org>1997-09-30 18:08:11 +0000
commit556ef9057383b8054c8c45eb7d4314799f53f5b0 (patch)
tree0081ddc684baec079a9ce4ca5661d882d2a00a4f /libexec/ypxfr
parente71cc90452001066c1efbeb7f81f12b988d33dfc (diff)
downloadFreeBSD-src-556ef9057383b8054c8c45eb7d4314799f53f5b0.zip
FreeBSD-src-556ef9057383b8054c8c45eb7d4314799f53f5b0.tar.gz
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.
Diffstat (limited to 'libexec/ypxfr')
-rw-r--r--libexec/ypxfr/ypxfr_main.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/libexec/ypxfr/ypxfr_main.c b/libexec/ypxfr/ypxfr_main.c
index 6e42c05..1c905cc 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 <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);
OpenPOWER on IntegriCloud