Skip to content

Commit

Permalink
fix: std::filesystem::path::iterator overflow issue
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Sep 27, 2024
1 parent 913e210 commit f8bd9c9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/tebako-dfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ static int dwarfs_process_inode(filesystem_v2& fs,
dwarfs::file_stat* st,
bool follow,
std::string& lnk,
// Using stdfs::path::iterator& below
// causes std::bad_alloc at ++p_iterator
// at least for gcc 12 headers. May be others as well.
stdfs::path::iterator& p_iterator,
stdfs::path& p_path)
{
Expand Down Expand Up @@ -308,8 +311,6 @@ static int dwarfs_find_inode(uint32_t start_from,

if (pi) {
ret = dwarfs_process_inode(p->fs, *pi, &dwarfs_st, follow_last, lnk, p_iterator, p_path);
//(3) other stat calls (lstat, relative etc)

while (p_iterator != p_path.end() && p_iterator->string() != "" && ret == DWARFS_IO_CONTINUE) {
auto inode = pi->inode_num();
auto mount_point = m_table.get(inode, p_iterator->string());
Expand Down Expand Up @@ -345,7 +346,9 @@ static int dwarfs_find_inode(uint32_t start_from,
ret = DWARFS_IO_ERROR;
}
}
++p_iterator;
if (p_iterator != p_path.end()) {
++p_iterator;
}
}
}
// Failed to find the start inode
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-defines-static.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static int scandir_c_test(void)
struct dirent** namelist;
int n, i;

#ifdef WITH_LINK_TESTS
#ifdef WITH_LINK_TESTS
const int N = 7;
#else
const int N = 6;
Expand Down
1 change: 0 additions & 1 deletion tests/tests-ln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ TEST_F(LnTests, tebako_lstat_level_2)
EXPECT_EQ(25, st.st_size);
}


TEST_F(LnTests, tebako_lstat_absolute_path_no_file)
{
struct STAT_TYPE st;
Expand Down

0 comments on commit f8bd9c9

Please sign in to comment.