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.
This commit is contained in:
Guilherme Janczak 2023-02-04 04:16:00 +00:00
parent 829632a735
commit 84314f013f
Signed by: guijan
GPG Key ID: 9F1927DAAC7F9DCD
3 changed files with 0 additions and 44 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;