Page MenuHomeFreeBSD

Fix off-by-one bug in btpand
ClosedPublic

Authored by dg612_cam.ac.uk on Jun 2 2024, 9:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 18 2025, 1:30 PM
Unknown Object (File)
Feb 14 2025, 11:44 PM
Unknown Object (File)
Feb 12 2025, 10:08 PM
Unknown Object (File)
Feb 12 2025, 10:03 PM
Unknown Object (File)
Feb 12 2025, 7:15 PM
Unknown Object (File)
Jan 29 2025, 7:42 AM
Unknown Object (File)
Jan 27 2025, 2:19 PM
Unknown Object (File)
Dec 28 2024, 2:19 PM
Subscribers

Details

Summary

ul reaches __arraycount(services) before the bound-check happens, causing undefined behaviour.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dg612_cam.ac.uk created this revision.

Please follow the wiki instructions and be sure to upload full context: https://wiki.freebsd.org/Phabricator#Create_a_Revision_via_Web_Interface

usr.sbin/bluetooth/btpand/btpand.c
146–151

Better as:

			for (ul = 0; ul < __arraycount(services); ul++) {
				if (strcasecmp(optarg, services[ul].name) == 0)
					break;
			}

			if (ul == __arraycount(services))
				errx(EXIT_FAILURE, "%s: unknown service", optarg);

or similar, IMO, as a standard idiom

The update looks good to my eyes

This revision is now accepted and ready to land.Jun 3 2024, 2:38 PM
This revision was automatically updated to reflect the committed changes.