From fc3b3d1120252ab32c26a704178e7f8b5c3f6d8e Mon Sep 17 00:00:00 2001 From: Thomas Koch Date: Wed, 11 Sep 2024 16:53:46 +0200 Subject: [PATCH] tlp-usblist: harden lsusb output parser Reference: * https://github.com/linrunner/TLP/issues/760#issuecomment-2341302184 --- tlp-usblist | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tlp-usblist b/tlp-usblist index 39480ec4..5713eacd 100644 --- a/tlp-usblist +++ b/tlp-usblist @@ -108,11 +108,13 @@ foreach my $udev (grep { ! /:/ } glob USBD . "/*") { # Output device list with attributes and drivers foreach (`lsusb 2> /dev/null`) { my ($bus, $dev, $usbid, $desc) = /Bus (\S+) Device (\S+): ID (\S+)[ ]+(.*)/; - my $usbk = $bus . "_" . $dev; - $desc =~ s/\s+$//; - $desc ||= ""; - print "Bus $bus Device $dev ID $usbid $usbdevices{$usbk}[1] -- $desc (" - . usbdriverlist ($usbdevices{$usbk}[0]) . ")\n"; + if (length ($bus) and length ($dev) and length ($usbid) ) { + my $usbk = $bus . "_" . $dev; + $desc =~ s/\s+$//; + $desc ||= ""; + print "Bus $bus Device $dev ID $usbid $usbdevices{$usbk}[1] -- $desc (" + . usbdriverlist($usbdevices{$usbk}[0]) . ")\n"; + } } exit 0;