From e67c34f0cbacb31f56ad46510857acfe20c4db90 Mon Sep 17 00:00:00 2001
From: Roland McGrath <roland@gnu.org>
Date: Tue, 11 Jun 2002 21:40:58 +0000
Subject: 2002-06-08  Roland McGrath  <roland@frob.com>

	* dir.c (diskfs_direnter_hard): Use size_t for OLDSIZE.
	Fail with EOVERFLOW when it would exceed that width.
	* alloc.c, dir.c: Use %Ld format for ino_t values.
	* alloc.c (diskfs_alloc_node): Use %Ld format for blkcnt_t values.
---
 ufs/dir.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'ufs')

diff --git a/ufs/dir.c b/ufs/dir.c
index 3256bc42..b67e45f6 100644
--- a/ufs/dir.c
+++ b/ufs/dir.c
@@ -379,7 +379,7 @@ dirscanblock (vm_address_t blockaddr, struct node *dp, int idx,
 	  || DIRSIZ (DIRECT_NAMLEN (entry)) > read_disk_entry (entry->d_reclen)
 	  || memchr (entry->d_name, '\0', DIRECT_NAMLEN (entry)))
 	{
-	  fprintf (stderr, "Bad directory entry: inode: %d offset: %zd\n",
+	  fprintf (stderr, "Bad directory entry: inode: %Ld offset: %zd\n",
 		  dp->dn->number, currentoff - blockaddr + idx * DIRBLKSIZ);
 	  return ENOENT;
 	}
@@ -502,7 +502,7 @@ diskfs_direnter_hard(struct node *dp,
   vm_address_t fromoff, tooff;
   int totfreed;
   error_t err;
-  off_t oldsize = 0;
+  size_t oldsize = 0;
 
   assert (ds->type == CREATE);
 
@@ -585,6 +585,12 @@ diskfs_direnter_hard(struct node *dp,
       assert (needed <= DIRBLKSIZ);
 
       oldsize = dp->dn_stat.st_size;
+      if ((off_t)(oldsize + DIRBLKSIZ) != dp->dn_stat.st_size)
+	{
+	  /* We can't possibly map the whole directory in.  */
+	  munmap ((caddr_t) ds->mapbuf, ds->mapextent);
+	  return EOVERFLOW;
+	}
       while (oldsize + DIRBLKSIZ > dp->allocsize)
 	{
 	  err = diskfs_grow (dp, oldsize + DIRBLKSIZ, cred);
-- 
cgit v1.2.3