-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[CHIPTOOL] Fix AddArgument for ByteSpan when content is hexstring #38838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aeb453c
to
d9330a2
Compare
PR #38838: Size comparison from 1f6aada to d9330a2 Full report (46 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, nrfconnect, psoc6, qpg, stm32, telink, tizen)
|
d9330a2
to
9041fa4
Compare
PR #38838: Size comparison from 1f6aada to 9041fa4 Full report (3 builds for cc32xx, stm32)
|
PR #38838: Size comparison from 1f6aada to 6f84ec7 Full report (75 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request changes: pointer to value on the stack seems to escape.
|
||
if (err != CHIP_NO_ERROR) | ||
{ | ||
if (buffer != nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's log the error.
|
||
arg.type = ArgumentType::OctetString; | ||
arg.name = name; | ||
arg.value = reinterpret_cast<void *>(&newValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are passing in a void pointer to a value on the stack. That cannot be good. How was this tested?
@kliffwong the statement Since this is in test code (i.e. chip tool) it seems generally ok to just have manual test, but it does have to be described in detail. |
PR #38838: Size comparison from d0ac18d to 1afec32 Full report (73 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
|
1afec32
to
a3c5850
Compare
PR #38838: Size comparison from df611f5 to a3c5850 Full report (70 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, psoc6, qpg, stm32, telink, tizen)
|
8238c8b
to
07e6698
Compare
PR #38838: Size comparison from 6667bf2 to 07e6698 Full report (27 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, nrfconnect, qpg, stm32, telink, tizen)
|
07e6698
to
dfdd368
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this PR description, this bit:
./chip-tool thermostat set-active-preset-request hex:<Handle> <nodeid> <endpoint>
seems to work fine for me: if I pass hex:aabb12
as the first arg, those are the bytes that the server gets. So I am not sure what this is trying to fix exactly or what sorts of "manual testing" were were done.
@@ -710,6 +710,37 @@ size_t Command::AddArgument(const char * name, chip::CharSpan * value, const cha | |||
size_t Command::AddArgument(const char * name, chip::ByteSpan * value, const char * desc, uint8_t flags) | |||
{ | |||
Argument arg; | |||
|
|||
// if the value is a hex string, we need to convert it from hex to bytes | |||
if ((value->size() > kHexStringPrefixLen) && IsHexString((const char *) value->data())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes no sense. The way this works is that AddArgument registers a memory location where the value will live later when we have a value. At the point where this is called, value->size()
is 0 at best (if it's a non-optional argument), and garbage at worst, because value
might in fact be a reinterpret_cast pointer to an Optional<ByteSpan>
here (if the kOptional flag is set).
The hex string detection should (and does) happen during the actual argument decoding, which is what will fill in the ByteSpan here. In particular, this will happen in Command::InitArgument
.
Testing
./chip-tool thermostat set-active-preset-request hex:<Handle> <nodeid> <endpoint>
./chip-tool thermostat set-active-schedule-request hex:<Handle> <nodeid> <endpoint>
<Handle>
as String to the node, which does not comply with the format used in./chip-tool thermostat write presets/schedules <arg> <nodeid> <endpoint>
<Handle>
and already parse the<Handle>
from HexString to number with this fix