[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: symlink/readlink and trailing slash
From: |
Ben Pfaff |
Subject: |
Re: symlink/readlink and trailing slash |
Date: |
Mon, 21 Sep 2009 14:51:37 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Eric Blake <address@hidden> writes:
> +/* Create a symlink, but reject trailing slash. */
> +int
> +rpl_symlink (char const *contents, char const *name)
> +{
> + size_t len = strlen (name);
> + if (name[len - 1] == '/')
> + {
If name is "" then the "if" statement will reference name[-1].
> +int
> +main ()
> +{
> + /* Remove any leftovers from a previous partial run. */
> + ASSERT (system ("rm -rf " BASE "*") == 0);
> +
> + if (symlink ("nowhere", BASE "link1"))
> + {
> + fputs ("skipping test: symlinks not supported on this filesystem\n",
> + stderr);
Should this print the specific error that was encountered? I
suspect that might be handy for debugging.
> +ssize_t
> +rpl_readlink (const char *name, char *buf, size_t bufsize)
> +{
> + size_t len = strlen (name);
> + if (name[len - 1] == '/')
> + {
Again, accesses name[-1] if name is "".
--
"The road to hell is paved with convenient shortcuts."
--Peter da Silva