Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Oct 2007 19:27:59 +0100
From:      Martin Kammerhofer <dada@sbox.tugraz.at>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/117687: [patch] fstab(5) format cannot handle spaces
Message-ID:  <200710301827.l9UIRxMt009382@pluto.tugraz.at>
Resent-Message-ID: <200710301920.l9UJK11p099056@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         117687
>Category:       bin
>Synopsis:       [patch] fstab(5) format cannot handle spaces
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 30 19:20:00 UTC 2007
>Closed-Date:
>Last-Modified:
>Originator:     Martin Kammerhofer
>Release:        FreeBSD 6.3-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD Martin.liebt.Susi 6.3-PRERELEASE FreeBSD 6.3-PRERELEASE #2: Sun Oct 28 16:05:41 CET 2007 toor@Martin.liebt.Susi:/usr/obj/usr/src/sys/P2B-S i386
>Description:

Fields in /etc/fstab are separated with spaces and/or TAB characters.
No quoting/escaping mechanism is defined, therefore fields cannot
contain embedded SP or TAB characters.  This is very rarely a problem
but can become a nuisance in dual boot configurations where access to
NTFS and/or VFAT partitions is needed.

The first fstab(5) field (special device name) can contain embedded
spaces when GEOM_LABEL is used.  It is not unusual to name logical
partitions like e.g. "BART'S PICTURES" or "MY MOVIES".  Using
glabel(8) these would result in special devices named like
/dev/msdosfs/BART\'S\ PICTURES and /dev/ntfs/MY\ MOVIES.

Since path names can contain spaces there is obviously a possibility
that a mount point directory's path contains white space.

When all setup/configuration is done manually, one can work around the
cases above by restricting oneself to disk labels and mount paths
without white space.  However why impose that restriction when it can
be lifted trivially with five added lines of code?  And what about the
cases where /etc/fstab is auto-generated by say an installer program
or the auto-configuration script of a live CD/DVD?

Compatibility note: Escaping space as \040 is compatible with Linux's
fstab(5).  Backward compatibility should be no problem, except for the
extremely unlikely case of an existing /etc/fstab which contains a
*literal* pattern of \^C, \M-C, \M^C or \577 (cf. vis(3)).

>How-To-Repeat:
>Fix:

Patch below is against RELENG_6 but differences to -current are
minimal.  Manpage patch also removes references to block devices.
They are gone for about 8 years now.

--- /usr/src/lib/libc/gen/fstab.c	2007-10-29 08:58:18.000000000 +0100
+++ fstab.c	2007-10-29 08:54:56.000000000 +0100
@@ -49,6 +49,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <vis.h>
 #include "un-namespace.h"
 
 static FILE *_fs_fp;
@@ -155,9 +156,13 @@
 		_fs_fstab.fs_spec = cp;
 		if (!_fs_fstab.fs_spec || *_fs_fstab.fs_spec == '#')
 			continue;
+		if (strunvis(cp, cp) <= 0)
+			goto bad;
 		while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
 			;
 		_fs_fstab.fs_file = cp;
+		if (strunvis(cp, cp) <= 0)
+			goto bad;
 		fixfsfile();
 		while ((cp = strsep(&p, " \t\n")) != NULL && *cp == '\0')
 			;
--- /usr/src/share/man/man5/fstab.5	2007-10-29 11:15:18.000000000 +0100
+++ fstab.5	2007-10-29 11:17:32.000000000 +0100
@@ -32,7 +32,7 @@
 .\"     @(#)fstab.5	8.1 (Berkeley) 6/5/93
 .\" $FreeBSD: src/share/man/man5/fstab.5,v 1.26 2004/07/03 18:29:22 ru Exp $
 .\"
-.Dd June 5, 1993
+.Dd October 29, 2007
 .Dt FSTAB 5
 .Os
 .Sh NAME
@@ -64,21 +64,20 @@
 .Pp
 The first field,
 .Pq Fa fs_spec ,
-describes the block special device or
+describes the special device or
 remote file system to be mounted.
-For file systems of type
-.Em ufs ,
-the special file name is the block special file name,
-and not the character special file name.
-If a program needs the character special file name,
-the program must create it by appending a ``r'' after the
-last ``/'' in the special file name.
 .Pp
 The second field,
 .Pq Fa fs_file ,
 describes the mount point for the file system.
 For swap partitions, this field should be specified as ``none''.
 .Pp
+The first and second field are decoded with the
+.Xr strunvis 3
+function, therefore spaces in the mount point path can be escaped as
+.Ql \e040
+\&.
+.Pp
 The third field,
 .Pq Fa fs_vfstype ,
 describes the type of the file system.
@@ -208,7 +207,7 @@
 #define	FSTAB_XX	"xx"	/* ignore totally */
 
 struct fstab {
-	char	*fs_spec;	/* block special device name */
+	char	*fs_spec;	/* special device name */
 	char	*fs_file;	/* file system path prefix */
 	char	*fs_vfstype;	/* File system type, ufs, nfs */
 	char	*fs_mntops;	/* Mount options ala -o */
@@ -242,6 +241,7 @@
 .Xr mount 8 ,
 .Xr quotacheck 8 ,
 .Xr quotaon 8 ,
+.Xr strunvis 3 ,
 .Xr swapon 8 ,
 .Xr umount 8
 .Sh HISTORY


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710301827.l9UIRxMt009382>