[net.bugs.4bsd] 4.?bsd dbm's store

ado@elsie.UUCP (Arthur David Olson) (04/10/85)

Index:		lib/libdbm/dbm.c Fix

Description:
	4.?bsd dbm's store function misbehaves if the sum of the key data
	size and content data size is either 1018 or 1019.

Repeat-By:
	Compile this program with the "dbm" library:

		typedef struct {
			char *	dptr;
			int	dsize;
		} datum;

		char	buf[1024];

		main(argc, argv)
		int	argc;
		char *	argv[];
		{
			int	result;
			datum	key;
			datum	content;

			key.dptr = content.dptr = buf;
			key.dsize = atoi(argv[1]);
			content.dsize = 0;
			creat("fake.dir", 0600);
			creat("fake.pag", 0600);
			dbminit("fake");
			result = store(key, content);
			printf("%d\n", result);
		}

	Then run the program.  If you use commands such as
		a.out 0
		a.out 1
		...
		a.out 1017
	things go swimmingly.  If you use commands such as
		a.out 1019
		a.out 1020
		...
	an error message is (correctly) produced.  But if you use either
	the command
		a.out 1018
	or
		a.out 1019
	things go wild.

Fix:
	As usual, the trade secret status of the code involved precludes a
	clearer posting.  The fix is to change one line in "dbm.c"; it
	causes an error message to be produced in the 1018/1019 cases:

		#ifdef OLDVERSION
			if(key.dsize+dat.dsize+2*sizeof(short) >= PBLKSIZ) {
		#else
			if(key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ) {
		#endif
--
Bugs is a Warner Brothers trademark
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks