public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jakub Jermar <jermar@itbs.cz>
To: linux-kernel@vger.kernel.org
Cc: torvalds@osdl.org
Subject: [PATCH] bfs filesystem read past the end of dir
Date: Wed,  5 May 2004 03:25:24 +0200	[thread overview]
Message-ID: <1083720324.4098428453030@mail.itbs.cz> (raw)

Hi,

I found out that BFS filesystem will eventually try to read and interpret garbage past the end of 
directory in bfs_add_entry(). If the garbage (interpreted as i-node number) is not set to zero (does it 
have to be?) bfs_add_entry() will consider it a regular directory entry. 

This causes weird things like this:
# touch a
# rm a
# ls
# touch b
# ls
a

My patch detects an attempt to read past the end of directory and explicitly clears the garbage that 
represents i-node number. Thus the correct behaviour is achieved.

Could you take a look at the patch and share your thoughts?

Thanks,
Jakub

diff -Nru linux-2.6.5/fs/bfs/dir.c linux-2.6.5-bfs-patch/fs/bfs/dir.c
--- linux-2.6.5/fs/bfs/dir.c    2004-04-04 05:38:13.000000000 +0200
+++ linux-2.6.5-bfs-patch/fs/bfs/dir.c  2004-05-05 01:28:41.000000000 +0200
@@ -274,7 +274,7 @@
 {
        struct buffer_head * bh;
        struct bfs_dirent * de;
-       int block, sblock, eblock, off;
+       int block, sblock, eblock, off, eoff;
        int i;

        dprintf("name=%s, namelen=%d\n", name, namelen);
@@ -286,12 +286,17 @@

        sblock = BFS_I(dir)->i_sblock;
        eblock = BFS_I(dir)->i_eblock;
+       eoff = dir->i_size % BFS_BSIZE;
        for (block=sblock; block<=eblock; block++) {
                bh = sb_bread(dir->i_sb, block);
                if(!bh)
                        return -ENOSPC;
                for (off=0; off<BFS_BSIZE; off+=BFS_DIRENT_SIZE) {
                        de = (struct bfs_dirent *)(bh->b_data + off);
+                       if (block==eblock && off>=eoff) {
+                               /* Do not read/interpret the garbage in the end of eblock. */
+                               de->ino = 0;
+                       }
                        if (!de->ino) {
                                if ((block-sblock)*BFS_BSIZE + off >= dir->i_size) {
                                        dir->i_size += BFS_DIRENT_SIZE;


                 reply	other threads:[~2004-05-05  0:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1083720324.4098428453030@mail.itbs.cz \
    --to=jermar@itbs.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox