From owner-freebsd-bugs@FreeBSD.ORG Tue Oct 30 19:20:03 2007 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F367F16A475 for ; Tue, 30 Oct 2007 19:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C056413C4C3 for ; Tue, 30 Oct 2007 19:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.1/8.14.1) with ESMTP id l9UJK1ih099057 for ; Tue, 30 Oct 2007 19:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.1/8.14.1/Submit) id l9UJK11p099056; Tue, 30 Oct 2007 19:20:01 GMT (envelope-from gnats) Resent-Date: Tue, 30 Oct 2007 19:20:01 GMT Resent-Message-Id: <200710301920.l9UJK11p099056@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Martin Kammerhofer Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F3BC16A469 for ; Tue, 30 Oct 2007 19:12:35 +0000 (UTC) (envelope-from dada@pluto.tugraz.at) Received: from mailrelay.tugraz.at (mailrelay.tu-graz.ac.at [129.27.2.202]) by mx1.freebsd.org (Postfix) with ESMTP id C626E13C4A8 for ; Tue, 30 Oct 2007 19:12:34 +0000 (UTC) (envelope-from dada@pluto.tugraz.at) Received: from pluto.tugraz.at (pluto.tu-graz.ac.at [129.27.3.200]) by mailrelay1.tugraz.at (8.14.1/8.14.1) with ESMTP id l9UIS5eh020520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 30 Oct 2007 19:28:05 +0100 (CET) Received: from pluto.tugraz.at (localhost.localdomain [127.0.0.1]) by pluto.tugraz.at (8.13.8/8.13.8) with ESMTP id l9UIRxO5009383 for ; Tue, 30 Oct 2007 19:27:59 +0100 Received: (from dada@localhost) by pluto.tugraz.at (8.13.8/8.13.8/Submit) id l9UIRxMt009382; Tue, 30 Oct 2007 19:27:59 +0100 Message-Id: <200710301827.l9UIRxMt009382@pluto.tugraz.at> Date: Tue, 30 Oct 2007 19:27:59 +0100 From: Martin Kammerhofer To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/117687: [patch] fstab(5) format cannot handle spaces X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Martin Kammerhofer List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2007 19:20:03 -0000 >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 #include #include +#include #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: