Commit 55ecde7f authored by Andy Hawkins's avatar Andy Hawkins Committed by Simon Kelley

Inotify: Ignore backup files created by editors

Use strlen to determine the length of the filename returned by
inotify, as in->len refers to the length of the buffer containing
the name, not the length of the name itself.

http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2018q1/011950.htmlSigned-off-by: default avatarAndy Hawkins <andy@gently.org.uk>

Patch further modified by simon@thekelleys.org to avoid
out-of-bounds array access with an empty string, call strlen once,
and reverse order of filename verifcation and resolv-file test.
parent 6b54d69a
...@@ -227,19 +227,21 @@ int inotify_check(time_t now) ...@@ -227,19 +227,21 @@ int inotify_check(time_t now)
for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len) for (p = inotify_buffer; rc - (p - inotify_buffer) >= (int)sizeof(struct inotify_event); p += sizeof(struct inotify_event) + in->len)
{ {
in = (struct inotify_event*)p; size_t namelen;
for (res = daemon->resolv_files; res; res = res->next) in = (struct inotify_event*)p;
if (res->wd == in->wd && in->len != 0 && strcmp(res->file, in->name) == 0)
hit = 1;
/* ignore emacs backups and dotfiles */ /* ignore emacs backups and dotfiles */
if (in->len == 0 || if (in->len == 0 || (namelen = strlen(in->name)) == 0 ||
in->name[in->len - 1] == '~' || in->name[namelen - 1] == '~' ||
(in->name[0] == '#' && in->name[in->len - 1] == '#') || (in->name[0] == '#' && in->name[namelen - 1] == '#') ||
in->name[0] == '.') in->name[0] == '.')
continue; continue;
for (res = daemon->resolv_files; res; res = res->next)
if (res->wd == in->wd && strcmp(res->file, in->name) == 0)
hit = 1;
for (ah = daemon->dynamic_dirs; ah; ah = ah->next) for (ah = daemon->dynamic_dirs; ah; ah = ah->next)
if (ah->wd == in->wd) if (ah->wd == in->wd)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment