git: 000755e790df - stable/14 - bluetooth-config: Fix command line parsing
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 20 Jul 2025 09:12:01 UTC
The branch stable/14 has been updated by lme:
URL: https://cgit.FreeBSD.org/src/commit/?id=000755e790dfd6c78a87c10133c46b55b634ffab
commit 000755e790dfd6c78a87c10133c46b55b634ffab
Author: Dirk Engling <erdgeist@erdgeist.org>
AuthorDate: 2025-07-13 09:25:24 +0000
Commit: Lars Engels <lme@FreeBSD.org>
CommitDate: 2025-07-20 09:10:45 +0000
bluetooth-config: Fix command line parsing
This addresses the problems encountered when parsing options in bluetooth-config.
- the optional parameters were not properly shifted after consumption
- the command line parameter count was checked before getopts and not after
Reported by: sjg
Approved by: kp
MFC after: 7 days
Event: Berlin Hackathon 202507
Differential Revision: <https://reviews.freebsd.org/D51281>
(cherry picked from commit 5031da20599bb1163f0e8d1c4b415ab3bbebce00)
---
usr.sbin/bluetooth/bluetooth-config/bluetooth-config.sh | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/usr.sbin/bluetooth/bluetooth-config/bluetooth-config.sh b/usr.sbin/bluetooth/bluetooth-config/bluetooth-config.sh
index 48a399a82fc7..148325fcecbc 100755
--- a/usr.sbin/bluetooth/bluetooth-config/bluetooth-config.sh
+++ b/usr.sbin/bluetooth/bluetooth-config/bluetooth-config.sh
@@ -17,7 +17,7 @@ main() {
unset node device started bdaddresses retry
# Only one command at the moment is scan (+ add)
-[ "$#" -eq 1 -a "$1" = "scan" ] || print_syntax
+[ "$1" = "scan" ] || print_syntax
shift
# Get command line options
@@ -28,6 +28,12 @@ while getopts :d:n: arg; do
?) print_syntax;;
esac
done
+shift "$((OPTIND-1))"
+
+# If there's leftover parameters, print usage
+[ "$#" -eq 0 ] || print_syntax
+shift
+
# No use running without super user rights
if [ $( id -u ) -ne 0 ]; then