[U-Boot] [PATCH 3/3] fs-test: Add test for a filename using '..' to go back to the root

Tuomas Tynkkynen tuomas.tynkkynen at iki.fi
Sun Sep 24 22:35:58 UTC 2017


On 09/25/2017 12:53 AM, Rob Clark wrote:
> On Sun, Sep 24, 2017 at 5:38 PM, Tom Rini <trini at konsulko.com> wrote:
>> On Mon, Sep 25, 2017 at 12:07:36AM +0300, Tuomas Tynkkynen wrote:
>>
>> Can you post, unrelated, the code that totally crashed sandbox?  Maybe
>> that's a problem we need to fix too :)
> 
> jfwiw, I've started looking at the fat_write code, so even a
> failing/crashing test is useful.
> 

On top of these three (also attached to avoid whitespace damage):

diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh
index a8a55e41fc..eccc03a513 100755
--- a/test/fs/fs-test.sh
+++ b/test/fs/fs-test.sh
@@ -110,7 +110,7 @@ function create_image() {
         # Create image if not already present - saves time, while debugging
         case "$2" in
                 fat16)
-               MKFS_OPTION="-F 16"
+               MKFS_OPTION="-F 16 -r 8192"
                 FS_TYPE="fat"
                 ;;
                 fat32)
@@ -363,6 +363,10 @@ function create_files() {
                         &> /dev/null
         fi

+       for i in $(seq 1 256); do
+               sudo touch "$MOUNT_DIR/LONGNAME$(head -c 240 /dev/zero | 
tr '\0' 'X').$i"
+       done
+
         # Create a small file in this image.
         if [ ! -f "${MB1}" ]; then
                 sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \
@@ -570,7 +574,7 @@ TOTAL_PASS=0
  # In each loop, for a given file system image, we test both the
  # fs command, like load/size/write, the file system specific command
  # like: ext4load/ext4size/ext4write and the sb load/ls/save commands.
-for fs in ext4 fat16 fat32; do
+for fs in fat16; do

         echo "Creating $fs image if not already present."
         IMAGE=${IMG}.${fs}.img

Basically the problem is that curclust for the root directory is not <= 
1 but rather some large positive value (0x01fffffe) in the following 
snippet in fat_write.c:

>  867                 /*
>  868                  * In FAT16/12, the root dir is locate before data area, shows
>  869                  * in following:
>  870                  * -------------------------------------------------------------
>  871                  * | Boot | FAT1 & 2 | Root dir | Data (start from cluster #2) |
>  872                  * -------------------------------------------------------------
>  873                  *
>  874                  * As a result if curclust is in Root dir, it is a negative
>  875                  * number or 0, 1.
>  876                  *
>  877                  */
>  878                 if (mydata->fatsize != 32 && (int)curclust <= 1) {
>  879                         /* Current clust is in root dir, set to next clust */
>  880                         curclust++;

With fsdata->data_begin = 896,
      fsdata->rootdir_sect = 640,
      fsdata->clust_size = 128,
indeed sect_to_clust(rootdir_sect) doesn't underflow enough to be 
negative but ends up 0x01fffffe. That hack really needs excising from 
the tree...

Another fun thing that needs handling is that the root directory need 
not be a multiple of cluster size, being a multiple of sector size is 
enough according to fatgen103.pdf...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: crash.diff
Type: text/x-patch
Size: 1046 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170925/4b497930/attachment.bin>


More information about the U-Boot mailing list