From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KV9LF-00052N-RI for qemu-devel@nongnu.org; Mon, 18 Aug 2008 14:20:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KV9LF-00050z-30 for qemu-devel@nongnu.org; Mon, 18 Aug 2008 14:20:33 -0400 Received: from [199.232.76.173] (port=46082 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KV9LE-00050i-VV for qemu-devel@nongnu.org; Mon, 18 Aug 2008 14:20:33 -0400 Received: from mx1.redhat.com ([66.187.233.31]:50879) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KV9LE-0003Lr-HN for qemu-devel@nongnu.org; Mon, 18 Aug 2008 14:20:32 -0400 Date: Mon, 18 Aug 2008 19:20:29 +0100 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] pty/tty functions for BSD too Message-ID: <20080818182029.GA9392@redhat.com> References: <20080818105912.GF4686@implementation.uk.xensource.com> <48A981F1.6070606@codemonkey.ws> <20080818142333.GQ4686@implementation.uk.xensource.com> <20080818162618.GA20089@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Reply-To: "Daniel P. Berrange" , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org On Mon, Aug 18, 2008 at 09:08:50PM +0300, Blue Swirl wrote: > On 8/18/08, Blue Swirl wrote: > > On 8/18/08, Daniel P. Berrange wrote: > > > > > > [quote openpty(1)] > > > BUGS > > > Nobody knows how much space should be reserved for name. So, call- > > > ing openpty() or forkpty() with non-NULL name may not be secure. > > > [/quote] > > > > > > Maybe in theory, but in practice the name will be > > /dev/pty[0-9a-z][a-z] or /dev/pts/[0-9]* or something similar. Even if > > they are not, PATH_MAX should be enough. > > > > > > > If BSD has no other way to determine the PTY name, then at least it > > > should be conditionalized so that systems with ptsname() use it, only > > > falling back to using the 'name' arg to openpty() for OS lacking ptsname > > > > > > I'm not convinced (yet?) this will be worth it. > > Glibc uses an internal PATH_MAX buffer. If the name does not fit, the > buffer will be doubled in size: > http://sourceware.org/cgi-bin/cvsweb.cgi/libc/login/openpty.c?rev=1.8&content-type=text/x-cvsweb-markup&cvsroot=glibc > > But in practice the pty will be allocated using getpt(), which uses > hard coded ptmx name: > http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/linux/getpt.c?rev=1.10&content-type=text/x-cvsweb-markup&cvsroot=glibc > > And ptsname() is used to get the pty name, which uses either hard > coded buffer length of _PATH_DEVPTS or _PATH_TTY: > http://sourceware.org/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/linux/ptsname.c?rev=1.15&content-type=text/x-cvsweb-markup&cvsroot=glibc > > OpenBSD forces the name to be in format "/dev/ptyXX": > http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libutil/pty.c?rev=1.15&content-type=text/x-cvsweb-markup > > NetBSD is similar, except also /dev/ttyXX is possible: > http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libutil/pty.c?rev=1.29&content-type=text/x-cvsweb-markup > > I still maintain that in reality, PATH_MAX should be enough. Ok, I guess its safe enough in practice then. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|