add mkstemps, mkdtemp

Eric Blake ebb9@byu.net
Mon Jun 29 22:37:00 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 6/29/2009 6:51 AM:
> Updated patch.  Now that POSIX 2008 requires mkdtemp, we should also be
> implementing that function at the same time.  POSIX also requires mkdtemp
> to fail with EINVAL if there are not six trailing 'X' (with mktemp, the
> behavior with less than 6 'X' was implementation defined, but it is
> easiest to define it to do the same as mkdtemp).  mktemp is ELIX level 2,
> but I'm guessing that mkdtemp and mkstemps should be ELIX level 4.  Cygwin
> doesn't use newlib's mktemp.c any more (the getpid() implementation is
> puny, so cygwin replaced it with an arc4random() implementation).  Also,
> fixes a theoretical bug of moving into the suffix and calling isdigit on
> an 8-bit signed char if you have all 36**6 file name candidates occupied
> (in reality, I doubt anyone will ever have a file system that full).

one more tweak:

>    for (trv = path; *trv; ++trv)		/* extra X's get set to 0's */
>      continue;
> +  trv -= suffixlen;
> +  end = trv;
>    while (*--trv == 'X')

This line must be:
while (path < trv && *--trv == 'X')
to avoid reading beyond the bounds of path.  This fixes an existing bug in
mk[s]temp - consider:

char template[]="XXXXXXX"; // 7 'X'
mkstemp (template + 1);

which mistakenly changes template[0] (and by extension, that means mkstemp
could cause a sigsegv coredump if given a string of all 'X' starting at a
memory fence).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpIvWAACgkQ84KuGfSFAYCQVACgmiVI6t2M8kHsiZ03uzIFAS0J
2gQAn3BHie+NPpOOAXHZCi7fCvk8YGS/
=LSgj
-----END PGP SIGNATURE-----



More information about the Newlib mailing list