rpc doesn't check arg lengths
- Dominant language
- Python
- Stars
- 14
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
Related to #676
`rpc_v2` currently checks that arg_format length doesn't truncate any data you pass in with `*args`, but we did not backport that to `rpc` due to a worry that some corner cases may be missed in our existing solutions.
This issue is being filed just to track that and provide a reference that we should implement new RPCs using the rpc_v2 implementation, and to document the limitation of the original rpc method.
The rpc method in question:
https://github.com/iotile/coretools/blob/master/iotilecore/iotile/core/hw/proxy/proxy.py#L36
When `arg_format` is provided, `struct.pack` has behavior that truncates certain argcodes.
From python's struct doc, https://docs.python.org/2/library/struct.html,
> For the 's' format character, the count is interpreted as the size of the string, not a repeat count like for the other format characters; for example, '10s' means a single 10-byte string, while '10c' means 10 characters. If a count is not given, it defaults to 1. For packing, **the string is truncated or padded with null bytes as appropriate to make it fit.** For unpacking, the resulting string always has exactly the specified number of bytes. As a special case, '0s' means a single, empty string (while '0c' means 0 characters).
`rpc_v2` moves to the method `pack_rpc_args` which does a validation check against the initial `struct.pack` to ensure we don't lose any bytes now (#678 )
Contributor guide
Assessment
This issue has not been assessed yet.