[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: symlink/readlink and trailing slash
From: |
Eric Blake |
Subject: |
Re: symlink/readlink and trailing slash |
Date: |
Tue, 22 Sep 2009 06:39:47 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 9/21/2009 4:27 PM:
> as well as audited other modules where I've recently added trailing slash
> checks.
This is the only instance I found in my audit of existing modules touched
in the last month; and it is actually a missed optimization rather than an
out-of-bounds reference (unless anyone knows of a platform where open("")
fails to give ENOENT).
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----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/
iEYEARECAAYFAkq4xZIACgkQ84KuGfSFAYAjyQCfbG/DpZHYz+OBbLSJqU81XG6H
jeYAoIplcTTfEUOTaqmrEpeLFZ24+4wp
=zcHG
-----END PGP SIGNATURE-----
>From f34e1ad57eebc72dbaa7aef0181c1a7d0afff1bf Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 21 Sep 2009 17:19:10 -0600
Subject: [PATCH] open, openat: minor optimization
* lib/open.c (open): If open succeeded, len is non-zero.
* lib/openat.c (rpl_openat): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 4 ++++
lib/open.c | 3 ++-
lib/openat.c | 3 ++-
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 33dc8ae..4abbe70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-09-22 Eric Blake <address@hidden>
+ open, openat: minor optimization
+ * lib/open.c (open): If open succeeded, len is non-zero.
+ * lib/openat.c (rpl_openat): Likewise.
+
link-follow: ensure correct result
* m4/fcntl_h.m4 (gl_FCNTL_H): Clean up temporary file.
* m4/link-follow.m4 (gl_FUNC_LINK_FOLLOWS_SYMLINK): Likewise, and
diff --git a/lib/open.c b/lib/open.c
index 08ecaff..7cc25bd 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -141,8 +141,9 @@ open (const char *filename, int flags, ...)
with ENOTDIR. */
if (fd >= 0)
{
+ /* We know len is positive, since open did not fail with ENOENT. */
size_t len = strlen (filename);
- if (len > 0 && filename[len - 1] == '/')
+ if (filename[len - 1] == '/')
{
struct stat statbuf;
diff --git a/lib/openat.c b/lib/openat.c
index 7e46a26..079039f 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -103,8 +103,9 @@ rpl_openat (int dfd, char const *filename, int flags, ...)
with ENOTDIR. */
if (fd >= 0)
{
+ /* We know len is positive, since open did not fail with ENOENT. */
size_t len = strlen (filename);
- if (len > 0 && filename[len - 1] == '/')
+ if (filename[len - 1] == '/')
{
struct stat statbuf;
--
1.6.5.rc1