Module Name:    src
Committed By:   martin
Date:           Wed Jun 26 17:11:51 UTC 2024

Modified Files:
        src/usr.sbin/btpand [netbsd-10]: btpand.c

Log Message:
Pull up following revision(s) (requested by plunky in ticket #727):

        usr.sbin/btpand/btpand.c: revision 1.9

Fix off-by-one bug in btpand

`ul` reaches `__arraycount(services)` before the bound-check happens, causing 
undefined behaviour.
from Dapeng Gao <dg612%cam.ac.uk@localhost> via FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.8.2.1 src/usr.sbin/btpand/btpand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btpand/btpand.c
diff -u src/usr.sbin/btpand/btpand.c:1.8 src/usr.sbin/btpand/btpand.c:1.8.2.1
--- src/usr.sbin/btpand/btpand.c:1.8	Wed May 18 13:56:32 2022
+++ src/usr.sbin/btpand/btpand.c	Wed Jun 26 17:11:51 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: btpand.c,v 1.8 2022/05/18 13:56:32 andvar Exp $	*/
+/*	$NetBSD: btpand.c,v 1.8.2.1 2024/06/26 17:11:51 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008-2009 Iain Hibbert
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008-2009 Iain Hibbert. All rights reserved.");
-__RCSID("$NetBSD: btpand.c,v 1.8 2022/05/18 13:56:32 andvar Exp $");
+__RCSID("$NetBSD: btpand.c,v 1.8.2.1 2024/06/26 17:11:51 martin Exp $");
 
 #include <sys/wait.h>
 
@@ -155,11 +155,14 @@ main(int argc, char *argv[])
 
 		case 's': /* service */
 		case 'S': /* service (no SDP) */
-			for (ul = 0; strcasecmp(optarg, services[ul].type); ul++) {
-				if (ul == __arraycount(services))
-					errx(EXIT_FAILURE, "%s: unknown service", optarg);
+			for (ul = 0; ul < __arraycount(services); ul++) {
+				if (strcasecmp(optarg, services[ul].type) == 0)
+					break;
 			}
 
+			if (ul == __arraycount(services))
+				errx(EXIT_FAILURE, "%s: unknown service", optarg);
+
 			if (ch == 's') {
 				service_type = services[ul].type;
 				service_name = services[ul].name;

Reply via email to