Fix segfault when moving file when using --monitor (#997)

* Fix segfault when attempting to perform a comparison on an inotify event when determining if event path is directory or file
This commit is contained in:
abraunegg 2020-07-22 06:54:35 +10:00 committed by GitHub
parent f6002311cd
commit beb737e903
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -239,6 +239,7 @@ final class Monitor
while (i < length) { while (i < length) {
inotify_event *event = cast(inotify_event*) &buffer[i]; inotify_event *event = cast(inotify_event*) &buffer[i];
string path; string path;
string evalPath;
// inotify event debug // inotify event debug
log.vdebug("inotify event wd: ", event.wd); log.vdebug("inotify event wd: ", event.wd);
log.vdebug("inotify event mask: ", event.mask); log.vdebug("inotify event mask: ", event.mask);
@ -280,26 +281,38 @@ final class Monitor
// if the event is not to be ignored, obtain path // if the event is not to be ignored, obtain path
path = getPath(event); path = getPath(event);
// skip events that should be excluded based on application configuration // configure the skip_dir & skip skip_file comparison item
if (isDir(path)) { evalPath = path.strip('.');
// The path that needs to be checked needs to include the '/'
// Skip events that should be excluded based on application configuration
// We cant use isDir or isFile as this information is missing from the inotify event itself
// Thus this causes a segfault when attempting to query this - https://github.com/abraunegg/onedrive/issues/995
// Based on the 'type' of event & object type (directory or file) check that path against the 'right' user exclusions
// Directory events should only be compared against skip_dir and file events should only be compared against skip_file
if (event.mask & IN_ISDIR) {
// The event in question contains IN_ISDIR event mask, thus highly likely this is an event on a directory
// This due to if the user has specified in skip_dir an exclusive path: '/path' - that is what must be matched // This due to if the user has specified in skip_dir an exclusive path: '/path' - that is what must be matched
if (selectiveSync.isDirNameExcluded(path.strip('.'))) { if (selectiveSync.isDirNameExcluded(evalPath)) {
// The path to evaluate matches a path that the user has configured to skip
goto skip; goto skip;
} }
} } else {
if (isFile(path)) { // The event in question missing the IN_ISDIR event mask, thus highly likely this is an event on a file
// The path that needs to be checked needs to include the '/'
// This due to if the user has specified in skip_file an exclusive path: '/path/file' - that is what must be matched // This due to if the user has specified in skip_file an exclusive path: '/path/file' - that is what must be matched
if (selectiveSync.isFileNameExcluded(path.strip('.'))) { if (selectiveSync.isFileNameExcluded(evalPath)) {
// The path to evaluate matches a file that the user has configured to skip
goto skip; goto skip;
} }
} }
// is the path, excluded via sync_list
if (selectiveSync.isPathExcludedViaSyncList(path)) { if (selectiveSync.isPathExcludedViaSyncList(path)) {
// The path to evaluate matches a directory or file that the user has configured not to include in the sync
goto skip; goto skip;
} }
// handle events // handle the inotify events
if (event.mask & IN_MOVED_FROM) { if (event.mask & IN_MOVED_FROM) {
log.vdebug("event IN_MOVED_FROM: ", path); log.vdebug("event IN_MOVED_FROM: ", path);
cookieToPath[event.cookie] = path; cookieToPath[event.cookie] = path;