This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Undefined behaviour in posix_openpt?
- From: Yaroslav Popovitch <yp at sot dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 11 Jun 2003 16:25:48 +0300 (EEST)
- Subject: Undefined behaviour in posix_openpt?
I was checking posix_openpt code(glibc-2.2.5 and glibc-2.2.93) and found
strange code.
There is a static variable( have_no_dev_ptmx )
which is not initialized by default
values. As result, the behaviour of function becomes undefined.
/* Open a master pseudo terminal and return its file descriptor. */
int
__posix_openpt (oflag)
int oflag;
{
static int have_no_dev_ptmx;
int fd;
if (!have_no_dev_ptmx) //undefined
{
fd = __open (_PATH_DEVPTMX, oflag);
if (fd != -1)
{
struct statfs fsbuf;
static int devpts_mounted;
/* Check that the /dev/pts filesystem is mounted
or if /dev is a devfs filesystem (this implies /dev/pts). */
if (devpts_mounted
|| (__statfs (_PATH_DEVPTS, &fsbuf) == 0
&& fsbuf.f_type == DEVPTS_SUPER_MAGIC)
|| (__statfs (_PATH_DEV, &fsbuf) == 0
&& fsbuf.f_type == DEVFS_SUPER_MAGIC))
{
/* Everything is ok. */
devpts_mounted = 1;
return fd;
}
/* If /dev/pts is not mounted then the UNIX98 pseudo terminals
are not usable. */
__close (fd);
have_no_dev_ptmx = 1;
}
else
{
if (errno == ENOENT || errno == ENODEV)
have_no_dev_ptmx = 1;
else
return -1;
}
}
return -1;
}
Cheers,YP
-
Mr. Yaroslav Popovitch yp@sot.com - tel. +372 6419975
SOT Finnish Software Engineering Ltd. - fax +372 6419876
Kreutzwaldi 7-4, 10124 TALLINN - http://www.sot.com
ESTONIA - http://sotlinux.net