fix an overrun bug in ffs and typos in testload.

This commit is contained in:
okuji 1999-09-06 09:41:28 +00:00
parent cb145227ae
commit f0ef2907eb
4 changed files with 58 additions and 19 deletions

View file

@ -1,3 +1,18 @@
1999-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* stage2/builtins.c (testload_func): Fix the typos: 0x2000000 ->
0x200000 and 0x3000000 -> 0x300000.
1999-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
From Hisazumi Kenji <nel@soraneko.com>:
* stage2/fsys_ffs.c (mapblock_offset): New variable.
(mapblock_bsize): Likewise.
(MAPBUF): New macro.
(MAPBUF_LEN): Likewise.
(ffs_mount): Set MAPBLOCK_OFFSET to -1.
(block_map): Added partial read support.
1999-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp> 1999-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* stage2/cmdline.c (find_command): If COMMAND is less than * stage2/cmdline.c (find_command): If COMMAND is less than

1
THANKS
View file

@ -14,6 +14,7 @@ Dan J. Walters <djw@cs.utexas.edu>
Edward Killips <ekillips@triton.net> Edward Killips <ekillips@triton.net>
Eric Hanchrow <erich@microsoft.com> Eric Hanchrow <erich@microsoft.com>
Heiko Schroeder <heiko@pool.informatik.rwth-aachen.de> Heiko Schroeder <heiko@pool.informatik.rwth-aachen.de>
Hisazumi Kenji <nel@soraneko.com>
Jochen Hoenicke <jochen@gnu.org> Jochen Hoenicke <jochen@gnu.org>
Klaus Reichl <klaus.reichl@alcatel.at> Klaus Reichl <klaus.reichl@alcatel.at>
Kunihiro Ishiguro <kunihiro@zebra.org> Kunihiro Ishiguro <kunihiro@zebra.org>

View file

@ -1244,8 +1244,8 @@ testload_func (char *arg, int flags)
*((int *) RAW_ADDR (0x30000c))); *((int *) RAW_ADDR (0x30000c)));
for (i = 0; i < 0x10ac0; i++) for (i = 0; i < 0x10ac0; i++)
if (*((unsigned char *) RAW_ADDR (0x2000000 + i)) if (*((unsigned char *) RAW_ADDR (0x200000 + i))
!= *((unsigned char *) RAW_ADDR (0x3000000 + i))) != *((unsigned char *) RAW_ADDR (0x300000 + i)))
break; break;
grub_printf ("Max is 0x10ac0: i=0x%x, filepos=0x%x\n", i, filepos); grub_printf ("Max is 0x10ac0: i=0x%x, filepos=0x%x\n", i, filepos);

View file

@ -67,11 +67,14 @@
/* used for filesystem map blocks */ /* used for filesystem map blocks */
static int mapblock; static int mapblock;
static int mapblock_offset;
static int mapblock_bsize;
/* pointer to superblock */ /* pointer to superblock */
#define SUPERBLOCK ((struct fs *) ( FSYS_BUF + 8192 )) #define SUPERBLOCK ((struct fs *) ( FSYS_BUF + 8192 ))
#define INODE ((struct icommon *) ( FSYS_BUF + 16384 )) #define INODE ((struct icommon *) ( FSYS_BUF + 16384 ))
#define MAPBUF ( FSYS_BUF + 24576 ) #define MAPBUF ( FSYS_BUF + 24576 )
#define MAPBUF_LEN 8192
int int
@ -87,31 +90,54 @@ ffs_mount (void)
retval = 0; retval = 0;
mapblock = -1; mapblock = -1;
mapblock_offset = -1;
return retval; return retval;
} }
static int static int
block_map (int file_block) block_map (int file_block)
{ {
int bnum; int bnum, offset, bsize;
if (file_block < NDADDR) if (file_block < NDADDR)
return (INODE->i_db[file_block]); return (INODE->i_db[file_block]);
if ((bnum = fsbtodb (SUPERBLOCK, INODE->i_ib[0])) != mapblock) /* If the blockmap loaded does not include FILE_BLOCK,
load a new blockmap. */
if ((bnum = fsbtodb (SUPERBLOCK, INODE->i_ib[0])) != mapblock
|| (mapblock_offset <= bnum && bnum <= mapblock_offset + mapblock_bsize))
{ {
if (!devread (bnum, 0, SUPERBLOCK->fs_bsize, (char *)MAPBUF)) if (MAPBUF_LEN < SUPERBLOCK->fs_bsize)
{
offset = ((file_block - NDADDR) % NINDIR (SUPERBLOCK));
bsize = MAPBUF_LEN;
if (offset + MAPBUF_LEN > SUPERBLOCK->fs_bsize)
offset = (SUPERBLOCK->fs_bsize - MAPBUF_LEN) / sizeof (int);
}
else
{
bsize = SUPERBLOCK->fs_bsize;
offset = 0;
}
if (! devread (bnum, offset * sizeof (int), bsize, (char *) MAPBUF))
{ {
mapblock = -1; mapblock = -1;
mapblock_bsize = -1;
mapblock_offset = -1;
errnum = ERR_FSYS_CORRUPT; errnum = ERR_FSYS_CORRUPT;
return -1; return -1;
} }
mapblock = bnum; mapblock = bnum;
mapblock_bsize = bsize;
mapblock_offset = offset;
} }
return (((int *) MAPBUF)[(file_block - NDADDR) % NINDIR (SUPERBLOCK)]); return (((int *) MAPBUF)[((file_block - NDADDR) % NINDIR (SUPERBLOCK))
- mapblock_offset]);
} }
@ -119,7 +145,7 @@ int
ffs_read (char *buf, int len) ffs_read (char *buf, int len)
{ {
int logno, off, size, map, ret = 0; int logno, off, size, map, ret = 0;
while (len && !errnum) while (len && !errnum)
{ {
off = blkoff (SUPERBLOCK, filepos); off = blkoff (SUPERBLOCK, filepos);
@ -169,13 +195,10 @@ loop:
/* load current inode (defaults to the root inode) */ /* load current inode (defaults to the root inode) */
if (!devread (fsbtodb (SUPERBLOCK, itod (SUPERBLOCK, ino)), if (!devread (fsbtodb (SUPERBLOCK, itod (SUPERBLOCK, ino)),
0, SUPERBLOCK->fs_bsize, (char *) FSYS_BUF)) ino % (SUPERBLOCK->fs_inopb) * sizeof (struct dinode),
return 0; /* XXX what return value? */ sizeof (struct dinode), (char *) INODE))
return 0; /* XXX what return value? */
memmove ((void *) INODE,
(void *) &(((struct dinode *) FSYS_BUF)[ino % (SUPERBLOCK->fs_inopb)]),
sizeof (struct dinode));
/* if we have a real file (and we're not just printing possibilities), /* if we have a real file (and we're not just printing possibilities),
then this is where we want to exit */ then this is where we want to exit */