From 89168f60aa971ea8290d91e05557c7a21cdb22f1 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 29 Apr 2007 20:52:12 -0400 Subject: snapshot of project "lynx", label v2-8-7dev_4b --- src/LYUtils.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/LYUtils.c') diff --git a/src/LYUtils.c b/src/LYUtils.c index 07802c20..8d5cca02 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -5866,6 +5866,34 @@ int remove(char *name) #endif #if defined(MULTI_USER_UNIX) + +#if defined(HAVE_LSTAT) && defined(S_IFLNK) +/* + * If IsOurFile() is checking a symbolic link, ensure that the target + * points to the user's file as well. + */ +static BOOL IsOurSymlink(const char *name) +{ + BOOL result = FALSE; + int size = LY_MAXPATH; + char *buffer = malloc(size); + + if (buffer != 0) { + while (readlink(name, buffer, size) == -1) { + buffer = realloc(buffer, size *= 2); + if (buffer == 0) + break; + } + } + if (buffer != 0) { + CTRACE2(TRACE_CFG, (tfp, "IsOurSymlink(%s -> %s)\n", name, buffer)); + result = IsOurFile(buffer); + FREE(buffer); + } + return result; +} +#endif + /* * Verify if this is really a file, not accessed by a link, except for the * special case of its directory being pointed to by a link from a directory @@ -5878,10 +5906,14 @@ BOOL IsOurFile(const char *name) if (!LYIsTilde(name[0]) && lstat(name, &data) == 0 - && S_ISREG(data.st_mode) - && (data.st_mode & (S_IWOTH | S_IWGRP)) == 0 - && data.st_nlink == 1 - && data.st_uid == getuid()) { + && ((S_ISREG(data.st_mode) + && (data.st_mode & (S_IWOTH | S_IWGRP)) == 0 + && data.st_nlink == 1 + && data.st_uid == getuid()) +#if defined(HAVE_LSTAT) && defined(S_IFLNK) + || (S_ISLNK(data.st_mode) && IsOurSymlink(name)) +#endif + )) { int linked = FALSE; /* -- cgit 1.4.1-2-gfad0