--- db_load.c.orig	Wed Aug  7 23:54:34 1996
+++ db_load.c	Tue Aug 20 16:04:19 1996
@@ -114,10 +114,10 @@
 					 const char *filename, int lineno));
 static int		getmlword __P((char *, int, FILE *, int));
 static int		getallwords __P((char *, int, FILE *, int));
-static u_long	wordtoul __P((char *));
-static u_long	datetosecs __P((char *, int *));
+static u_int32_t	wordtouint32 __P((char *));
+static u_int32_t	datetosecs __P((char *, int *));
 
-static int		wordtoul_error = 0;
+static int		wordtouint32_error = 0;
 static int		empty_token = 0;
 static int		getmlword_nesting = 0;
 
@@ -167,7 +167,7 @@
 	char tmporigin[MAXDNAME];
 	char buf[MAXDATA];
 	char data[MAXDATA];
-	const char *cp1, *op;
+	const char *op;
 	int c, someclass, class, type, dbflags, dataflags, multiline;
 	u_int32_t ttl;
 	struct databuf *dp;
@@ -179,8 +179,8 @@
 	int escape;
 	enum transport transport;
 	enum context context;
-	int sig_type;
-	u_int16_t keyflags;
+	u_int32_t sig_type;
+	u_int32_t keyflags;
 	int success;
 	int dateerror;
 #ifdef DO_WARN_SERIAL
@@ -697,7 +697,9 @@
 	 *		a string of base64 digits,
 	 *		skipping any embedded whitespace.
 	 */
-				int nk, al, pr, gotkey, klen;
+				u_int32_t al, pr;
+				int nk;
+				ssize_t klen;
 				char *expstart;
 				u_int expbytes, modbytes;
 
@@ -711,8 +713,8 @@
 					SETERR("No flags field");
 					goto err;
 				}
-				keyflags = wordtoul(buf);
-				if (wordtoul_error || 0xFFFF < keyflags)
+				keyflags = wordtouint32(buf);
+				if (wordtouint32_error || 0xFFFF < keyflags)
 					goto err;
 				if (keyflags & KEYFLAG_RESERVED_BITMASK) {
 					SETERR("Reserved flag bits are set");
@@ -721,12 +723,13 @@
 				PUTSHORT(keyflags, cp);
 
 			/*>>> Protocol (8-bit decimal) */
-				if (!getmlword((char*)buf, sizeof(buf), fp, 0)) {
+				if (!getmlword((char*)buf, sizeof(buf), fp, 0)
+				    ) {
 					SETERR("No protocol field");
 					goto err;
 				}
-				pr = wordtoul(buf);
-				if (wordtoul_error || 255 < pr)
+				pr = wordtouint32(buf);
+				if (wordtouint32_error || 255 < pr)
 					goto err;
 				*cp++ = (u_char) pr;
 
@@ -736,8 +739,8 @@
 					SETERR("No algorithm ID")
 					goto err;
 				}
-				al = wordtoul(buf);
-				if (wordtoul_error ||
+				al = wordtouint32(buf);
+				if (wordtouint32_error ||
 				    0 == al || 255 == al || 255 < al)
 					goto err;
 				*cp++ = (u_char) al;
@@ -889,7 +892,8 @@
 		   It's too crazy to run these pages of SIG code at the right
 		   margin.  I'm exdenting them for readability.
 		 */
-		int nk, al, pr, gotkey, siglen;
+		ssize_t siglen;
+		u_int32_t al;
 		u_int32_t signtime, exptime, timetilexp;
 		u_int32_t origTTL;
 		time_t now;
@@ -918,11 +922,11 @@
 			 * We'll also accept a numeric RR type,
 			 * for signing RR types that this version
 			 * of named doesn't yet understand.
-			 * In the T_ANY case, we rely on wordtoul
+			 * In the T_ANY case, we rely on wordtouint32
 			 * to fail when scanning the string "ANY".
 			 */
-			sig_type = wordtoul (buf);
-			if (wordtoul_error || sig_type > 0xFFFF) {
+			sig_type = wordtouint32 (buf);
+			if (wordtouint32_error || sig_type > 0xFFFF) {
 				SETERR("Unknown RR type in SIG record");
 				goto err;
 			}
@@ -936,8 +940,8 @@
 			SETERR("Missing algorithm ID");
 			goto err;
 		}
-		al = wordtoul(buf);
-		if (0 == al || wordtoul_error || 255 <= al)
+		al = wordtouint32(buf);
+		if (0 == al || wordtouint32_error || 255 <= al)
 			goto err;
 		data[i] = (u_char) al;
 		i++;
@@ -955,8 +959,8 @@
 		i++;
 
 		/*
-		 * OTTL (optional u_long) and
-		 * Texp (u_long date)
+		 * OTTL (optional u_int32_t) and
+		 * Texp (u_int32_t date)
 		 */
 		if (!getmlword((char *)buf, sizeof(buf), fp, 0)) {
 			SETERR("OTTL and expiration time missing");
@@ -976,8 +980,8 @@
 			i += 4;
 		} else {
 			/* Parse and output OTTL; scan TEXP */
-			origTTL = wordtoul(buf);
-			if (0 >= origTTL || wordtoul_error ||
+			origTTL = wordtouint32(buf);
+			if (0 >= origTTL || wordtouint32_error ||
 			    (origTTL > 0x7fffffff))
 				goto err;
 			cp = &data[i];
@@ -997,7 +1001,7 @@
 		PUTLONG(exptime, cp);
 		i += 4;
 
-		/* Tsig (u_long) */
+		/* Tsig (u_int32_t) */
 		if (!getmlword((char *)buf, sizeof(buf), fp, 0)) {
 			SETERR("Missing signature time");
 		 	goto err;
@@ -1016,8 +1020,8 @@
 			SETERR("Missing key footprint");
 		 	goto err;
 		}
-		n = wordtoul(buf);
-		if (wordtoul_error || n >= 0x0ffff) {
+		n = wordtouint32(buf);
+		if (wordtouint32_error || n >= 0x0ffff) {
 			SETERR("Invalid key footprint");
 			goto err;
 		}
@@ -1965,30 +1969,35 @@
 }
 
 /*
- * Converts a word to an u_long.  Error if any non-numeric
+ * Converts a word to a u_int32_t.  Error if any non-numeric
  * characters in the word, except leading or trailing white space.
  */
-static u_long
-wordtoul(buf)
+static u_int32_t
+wordtouint32(buf)
 	char *buf;
 {
 	u_long result;
+	u_int32_t res2;
 	char *bufend;
 
-	wordtoul_error = 0;
+	wordtouint32_error = 0;
 	result = strtoul(buf, &bufend, 0);
 	if (bufend == buf)
-		wordtoul_error = 1;
+		wordtouint32_error = 1;
 	else
 		while ('\0' != *bufend) {
 			if (isspace(*bufend))
 				bufend++;
 			else {
-				wordtoul_error = 1;
+				wordtouint32_error = 1;
 				break;
 			}
 		}
-	return (result);
+	/* Check for truncation between u_long and u_int32_t */
+	res2 = result;
+	if (res2 != result)		
+		wordtouint32_error = 1;
+	return (res2);
 }
 
 
@@ -2021,13 +2030,13 @@
    1 January 1970 (GMT assumed).  Format is yyyymmddhhmmss, all
    digits required, no spaces allowed.  */
 
-static u_long
+static u_int32_t
 datetosecs(cp, errp)
 	char *cp;
 	int *errp;
 {
 	struct tm time;
-	time_t result;
+	u_int32_t result;
 	int mdays, i;
 	static const int days_per_month[12] =
 		{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -2053,7 +2062,7 @@
 	 * we will do it by hand.  Roll up sleeves, curse the gods, begin!
 	 */
 
-#define	SECS_PER_DAY	(24*60*60)
+#define	SECS_PER_DAY	((u_int32_t)24*60*60)
 #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
 
 	result  = time.tm_sec;				/* Seconds */
@@ -2071,7 +2080,7 @@
 
 	/* First figure years without leapdays, then add them in.  */
 	/* The loop is slow, FIXME, but simple and accurate.  */
-	result += (time.tm_year - 70) * (SECS_PER_DAY*(time_t)365); /* Years */
+	result += (time.tm_year - 70) * (SECS_PER_DAY*365); /* Years */
 	for (i = 70; i < time.tm_year; i++)
 		if (isleap (1900+i)) 
 			result += SECS_PER_DAY;	/* Add leapday for prev year */

