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
F156904272: D45463.id139404.diff
Sun, May 17, 6:00 AM
F156882675: D45463.id139351.diff
Sun, May 17, 1:39 AM
F156820467: D45463.id139345.diff
Sat, May 16, 4:42 PM
Unknown Object (File)
Thu, May 14, 1:20 PM
Unknown Object (File)
Wed, May 13, 9:48 PM
Unknown Object (File)
Wed, May 13, 9:47 PM
Unknown Object (File)
Wed, May 13, 9:47 PM
Unknown Object (File)
Wed, May 13, 9:47 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 Skipped
Unit
Tests Skipped

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.