Skip to content

libusb: guard inaccessible usb devices from segfaults#40

Open
alexryndin wants to merge 1 commit intodesrod:mainfrom
alexryndin:fix-usb-eacces-segv
Open

libusb: guard inaccessible usb devices from segfaults#40
alexryndin wants to merge 1 commit intodesrod:mainfrom
alexryndin:fix-usb-eacces-segv

Conversation

@alexryndin
Copy link
Copy Markdown

Problem

pilot-link can crash while probing USB devices if the Palm device node exists but is not accessible to the current user.

In that case usb_open() may return NULL, but USB_poll() continues into the normal configuration path and later reaches code that assumes a valid libusb handle. On Arch Linux this reproduced as a SIGSEGV
when pilot-xfer -p usb: -l hit a Palm device under /dev/bus/usb/... without read/write access.

Fix

This change makes USB_poll() fail fast for inaccessible devices and cleanly reset state on early exit paths:

  • include <unistd.h> for access()
  • check /dev/bus/usb/<bus>/<device> before usb_open()
  • skip the device when read/write access is missing
  • handle usb_open() returning NULL
  • clear data->ref and USB_handle on early failure paths
  • avoid calling usb_close() on a null handle

Result

Instead of crashing, the USB probe now logs the permission problem and continues scanning devices.

Verification

Reproduced on Arch Linux with a Palm Tungsten E2 over USB:

  • before the patch: pilot-xfer -p usb: -l crashed with SIGSEGV after hitting an inaccessible /dev/bus/usb/... node
  • after the patch: the same command logs the access/open failure and exits cleanly without a core dump

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

Successfully merging this pull request may close these issues.

1 participant