[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [BusyBox] BusyBox 1.00-pre3 - SEGFAULT mount with /etc/filesystems
From:       Pete Flugstad <peteflugstad () mchsi ! com>
Date:       2003-09-29 21:05:29
[Download RAW message or body]

If you create a file /etc/filesystems and add a few lines to it, mount 
is supposed to test these filesystem types first and if they fail, 
then do the same with /proc/filesystems.

The code in mount_one looks like this:

     f = fopen("/etc/filesystems", "r");
     if (f) {
       while (fgets(buf, sizeof(buf), f)) {
           .... process /etc/filesystems,
           .... setting status to TRUE if one works
       }
       fclose(f);
      }

      if ((!f || read_proc) && !status) {
           f = bb_xfopen("/proc/filesystems", "r");

           while (fgets(buf, sizeof(buf), f) != NULL) {
               .... process /proc/filesystems,
               .... setting status to TRUE if one works
           }
       }
       fclose(f);  <<<  THIS ONE

The problem is if /etc/filesystems exists, and the device is mounted 
OK using a filesystem type from it, then the 2nd fclose is closing an 
already closed file.  This is causing a SEGFAULT on my system here 
(VIA C3 based).

Also, the return from opening /proc/filesystems is not checked.

I expect the 2nd block of code should probably look more like:

      if ((!f || read_proc) && !status) {
           f = bb_xfopen("/proc/filesystems", "r");
           if ( f ) {
               while (fgets(buf, sizeof(buf), f) != NULL) {
                   .... process /proc/filesystems,
                   .... setting status to TRUE if one works
               }
               fclose(f);
           }
       }

Or something like that.  Wrapping the 2nd while loop with the if ( f )
{ ... } and moving the fclose within that block.

Hope this makes sense.

Pete Flugstad



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic