The branch main has been updated by lme:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5031da20599bb1163f0e8d1c4b415ab3bbebce00

commit 5031da20599bb1163f0e8d1c4b415ab3bbebce00
Author:     Dirk Engling <erdge...@erdgeist.org>
AuthorDate: 2025-07-13 09:25:24 +0000
Commit:     Lars Engels <l...@freebsd.org>
CommitDate: 2025-07-13 09:25:24 +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>
---
 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

Reply via email to