[BusyBox] nfsmount pointer bug

Sauder, Vernon Vernon.Sauder at spirentcom.com
Thu May 6 03:10:30 UTC 2004


Hello again.
I found another simple bug that should be fixed. If "mount -a" is done when
2 NFS mounts are in fstab and they need to both have the "nolock" option (no
local portmap running), mount will do the second mount with the "lock"
option and timeout (take a very long time). This seems to be a pointer
problem. A pointer to strdup'd data is handed by pointer to nfsmount().
nfsmount() does not use it as a dynamically allocated pointer; it sets it to
point to a static structure. This is OK until the next mount is retrieved
from the fstab and the options from that are parsed. In the parsing
function, the pointer is xrealloc'd which frees the internal static memory
in nfsmount. The next call to nfsmount would have undefined behavior. Here
is the patch. It is against a recent CVS version. It is also quite simple.
(I have also attached it in the case that this emailer messes up the
formatting.) If there is a better or more correct way to fix this, let me
know.


** Fixed memory allocation problem
	-A fstab file with 2 nfs auto mounts would hang because the second
mount would
		mount as lock even if nolock was specified.
	-nfsmount redirected a pointer to static internal data
	-that pointer was later xrealloc'd which must have messed up the
internal data

--- busybox.old/util-linux/mount.c        2004-05-05 20:56:36.000000000
-0400
+++ busybox.new/util-linux/mount.c  2004-04-14 13:51:38.000000000 -0400
@@ -366,6 +366,7 @@
 {
        struct stat statbuf;
        char *string_flags = bb_xstrdup("");
+       char *string_flags2;
        char *extra_opts;
        int flags = 0;
        char *filesystemType = "auto";
@@ -461,12 +462,13 @@
                        filesystemType = bb_xstrdup(m->mnt_type);
                  singlemount:
                        extra_opts = string_flags;
+                       string_flags2 = string_flags;   /* nfsmount may
point this to its internal static data */
                        rc = EXIT_SUCCESS;
 #ifdef CONFIG_NFSMOUNT
                        if (strchr(device, ':') != NULL) {
                                filesystemType = "nfs";
                                if (nfsmount
-                                       (device, directory, &flags,
&extra_opts, &string_flags,
+                                       (device, directory, &flags,
&extra_opts, &string_flags2,
                                         1)) {
                                        bb_perror_msg("nfsmount failed");
                                        rc = EXIT_FAILURE;
@@ -474,7 +476,7 @@
                        }
 #endif
                        if (!mount_one
-                               (device, directory, filesystemType, flags,
string_flags,
+                               (device, directory, filesystemType, flags,
string_flags2,
                                 useMtab, fakeIt, extra_opts, TRUE, all)) {
                                rc = EXIT_FAILURE;
                        }



Vernon Sauder
www.spirentcom.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: mount.patch
Type: application/octet-stream
Size: 1972 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20040505/5845bb53/attachment.obj 


More information about the busybox mailing list