-
Notifications
You must be signed in to change notification settings - Fork 114
Calling startMonitoring() and stopMonitoring() multiple times causes segmentation fault (Linux, macOS) #57
Comments
Related to #53 |
I don't think calling them multiple times is the problem. var usbDetect = require('usb-detection');
usbDetect.startMonitoring();
usbDetect.stopMonitoring();
setTimeout(() => console.log('end'), 1000); If I comment out the line with Node Version: v12.8.0 By the way: The code above works just fine on MacOS. |
I can reproduce the problem on my Linux machine with the code posted by @PeterBurner . OS: Linux 5.3 Kali GNU/Linux Rolling 2019.4
Node: 13.5.0 |
I reproduce this situation in [email protected] on Node 12 and Mac. |
As @gre mentioned this can be reproduced on Mac with Node12. Could we update this issue's title + labels to reflect it better? 🌈 |
For 4.10, I was able to fix this with the following patch: linux_detection_fix_udev_mon_use_after_free.txt linux_detection_fix_udev_mon_use_after_free patchDescription: linux detection: fix udev mon use after free
TODO: Put a short summary on the line above and replace this paragraph
with a longer explanation of this change. Complete the meta-information
with other relevant fields (see below for details). To make it easier, the
information below has been extracted from the changelog. Adjust it or drop
it.
.
node-usb-detection (4.10.0-2) UNRELEASED; urgency=medium
.
[ Ken Fazzone ]
* Initial release
Author: Ken Fazzone <[email protected]>
---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2021-01-19
--- node-usb-detection-4.10.0.orig/src/detection_linux.cpp
+++ node-usb-detection-4.10.0/src/detection_linux.cpp
@@ -98,6 +98,7 @@ void Stop() {
uv_cond_destroy(¬ifyDeviceHandled);
udev_monitor_unref(mon);
+ mon = NULL;
udev_unref(udev);
}
@@ -226,19 +227,21 @@ static void cbWork(uv_work_t *req) {
if (!ret) continue;
if (ret < 0) break;
- dev = udev_monitor_receive_device(mon);
- if (dev) {
- if(udev_device_get_devtype(dev) && strcmp(udev_device_get_devtype(dev), DEVICE_TYPE_DEVICE) == 0) {
- if(strcmp(udev_device_get_action(dev), DEVICE_ACTION_ADDED) == 0) {
- WaitForDeviceHandled();
- DeviceAdded(dev);
- }
- else if(strcmp(udev_device_get_action(dev), DEVICE_ACTION_REMOVED) == 0) {
- WaitForDeviceHandled();
- DeviceRemoved(dev);
+ if(mon) {
+ dev = udev_monitor_receive_device(mon);
+ if (dev) {
+ if(udev_device_get_devtype(dev) && strcmp(udev_device_get_devtype(dev), DEVICE_TYPE_DEVICE) == 0) {
+ if(strcmp(udev_device_get_action(dev), DEVICE_ACTION_ADDED) == 0) {
+ WaitForDeviceHandled();
+ DeviceAdded(dev);
+ }
+ else if(strcmp(udev_device_get_action(dev), DEVICE_ACTION_REMOVED) == 0) {
+ WaitForDeviceHandled();
+ DeviceRemoved(dev);
+ }
}
+ udev_device_unref(dev);
}
- udev_device_unref(dev);
}
}
} |
Fix #57 Co-authored-by: Matt Bernhard <[email protected]> (@umbernhard) Co-authored-by: Dimitri Witkowski <[email protected]> (@antelle) Co-authored-by: Julian Waller <[email protected]> (@Julusian) Co-authored-by: Eric Eastwood <[email protected]> (@MadLittleMods)
In a simple node application, if you execute the folllowing code, you will either get segmentation fault or some memory corruption error on Ubuntu 16.04:
The text was updated successfully, but these errors were encountered: