Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOCTOU bug when adding a watcher #579

Open
matklad opened this issue Mar 22, 2024 · 1 comment
Open

TOCTOU bug when adding a watcher #579

matklad opened this issue Mar 22, 2024 · 1 comment

Comments

@matklad
Copy link

matklad commented Mar 22, 2024

See user visible bug report here: lomirus/live-server#73

I believe the following code is incorrect:

for entry in WalkDir::new(path)
.follow_links(true)
.into_iter()
.filter_map(filter_dir)
{
self.add_single_watch(entry.path().to_path_buf(), is_recursive, watch_self)?;
watch_self = false;
}

Here, we use walkdir to list paths, and then use inotify to watch the path. The problem is that between the moment that walkdir returned us a PathBut, and us giving this path to inotify to watch, the path can get deleted. This results in inotify returning a FileNotFound IO error, and notify bailing out with it all the way up to RecommendedWatcher::watch.

The expected behavior is for notify to either report removal for this path, or not report anything at all, but clearly not to crash.

EDIT: to clarify, the path in question is not the root path which we ask to watch, but some subdirectory of it

@matklad
Copy link
Author

matklad commented Mar 22, 2024

https://mail.gnome.org/archives/dashboard-hackers/2004-October/msg00022.html details a solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant