This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/6/head
in repository legacy-imlib2.
View the commit online.
commit 84314f013fc5cc1548e4c37b5ecfbdd20a0a0388
Author: Guilherme Janczak <[email protected]>
AuthorDate: Sat Feb 4 04:16:00 2023 +0000
remove bad unused function
__imlib_FileCanRead() suffers from TOCTTOU issues. The file behind the
path it takes as a parameter can change while the function executes, and
also between the function's return and the caller's use of the path.
The function is also unused, so just delete it.
---
src/lib/file.c | 16 ----------------
src/lib/file.h | 1 -
test/test_file.cpp | 27 ---------------------------
3 files changed, 44 deletions(-)
diff --git a/src/lib/file.c b/src/lib/file.c
index bfb5500..97ab0ea 100644
--- a/src/lib/file.c
+++ b/src/lib/file.c
@@ -181,22 +181,6 @@ __imlib_FileModDateFd(int fd)
return (st.st_mtime > st.st_ctime) ? st.st_mtime : st.st_ctime;
}
-int
-__imlib_FileCanRead(const char *s)
-{
- struct stat st;
-
- DP("%s: '%s'\n", __func__, s);
-
- if (__imlib_FileStat(s, &st))
- return 0;
-
- if (!(st.st_mode & (S_IRUSR | S_IRGRP | S_IROTH)))
- return 0;
-
- return access(s, R_OK) == 0 ? 1 : 0; // ??? TBD
-}
-
char **
__imlib_FileDir(const char *dir, int *num)
{
diff --git a/src/lib/file.h b/src/lib/file.h
index 2de9e16..ae7ce86 100644
--- a/src/lib/file.h
+++ b/src/lib/file.h
@@ -35,7 +35,6 @@ int __imlib_FileIsFile(const char *s);
int __imlib_FileIsDir(const char *s);
time_t __imlib_FileModDate(const char *s);
time_t __imlib_FileModDateFd(int fd);
-int __imlib_FileCanRead(const char *s);
char **__imlib_FileDir(const char *dir, int *num);
void __imlib_FileFreeDirList(char **l, int num);
diff --git a/test/test_file.cpp b/test/test_file.cpp
index dd69200..ce81ff4 100644
--- a/test/test_file.cpp
+++ b/test/test_file.cpp
@@ -117,33 +117,6 @@ TEST(FILE, file_is_dir)
EXPECT_EQ(rc, 0);
}
-TEST(FILE, file_can_read)
-{
- int rc;
-
- rc = __imlib_FileCanRead("./Makefile");
- EXPECT_EQ(rc, 1);
-
- rc = __imlib_FileCanRead(".");
- EXPECT_EQ(rc, 1);
-
- rc = __imlib_FileCanRead("./foob");
- EXPECT_EQ(rc, 0);
-
- rc = system("touch gylle");
- EXPECT_EQ(rc, 0);
- rc = __imlib_FileCanRead("gylle");
- EXPECT_EQ(rc, 1);
-
- rc = system("chmod 000 gylle");
- EXPECT_EQ(rc, 0);
- rc = __imlib_FileCanRead("gylle");
- EXPECT_EQ(rc, 0);
-
- rc = unlink("gylle");
- EXPECT_EQ(rc, 0);
-}
-
TEST(FILE, file_is_real_file)
{
int rc;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.