🐛[BUG] - registry_get_plugged_type
uses incorrect bounds-check for port index.
#623
Labels
bug
Something isn't working
Describe the bug
This is a fun one.
pros::c::registry_get_plugged_type
supposedly takes a zero-indexed smart port index and returns the assocaitedv5_device_e_t
.6
) if the provided port is out of range (docs claim the range is 0-20, which makes sense, given there are 21 smart ports and this argument is zero-indexed).-1
to intentionally overflow the return value (v5_device_e_t -- which the compiler assumes is a unsigned 8-bit integer) to255
(which is the value ofE_DEVICE_UNDEFINED
).Okay, so when you pass an out of bounds port,
registry_get_plugged_type
will returnE_DEVICE_UNDEFINED
(255 overflowed from -1) and seterrno
toENXIO
, right? Nope! Specifically when requesting port 21's plugged type (a supposedly out-of-bounds port),pros::c::registry_get_plugged_type
will return12
, which isE_DEVICE_ADI
. Huh?registry_get_plugged_type
bound-checks the port number againstVALIDATE_PORT_NO
, which uses a max input value of22
. This would work fine if the argument wasn't a zero-indexed port, but in this case it allows us to index intoregistry_types
one port index above the intended maximum. For some reason, this happens to be 12.V5_MAX_DEVICE_PORTS
which has some internal V5 device access stuff after the regular smart port indexes, andvexDeviceGetStatus
happens to storeINTERNAL_ADI_PORT
at index 21 (which is the brain's "internal ADI expander").To Reproduce
Expected behavior
Screenshots
N/A
Desktop (please complete the following information):
Additional context
Tested on PROS 3.8.0
The text was updated successfully, but these errors were encountered: