diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2021-05-22 02:09:24 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2021-05-22 02:11:32 +0200 |
commit | b421544094080dc0d7e37d2246356179c9265052 (patch) | |
tree | 7ce1eeb966d335e55b663ac81ff8baa46c7ff0e1 | |
parent | 1a288ccc6945dfa40a513ba5feb51d2c253d80e3 (diff) | |
download | psmq-b421544094080dc0d7e37d2246356179c9265052.tar.gz psmq-b421544094080dc0d7e37d2246356179c9265052.tar.bz2 psmq-b421544094080dc0d7e37d2246356179c9265052.zip |
psmq-common.h: fix invalid msg size for ioctl requests
ioctls have no topics thus strlen() cannot be run on them
when calculating real msg size.
We could get away with this bug since right now we have only
single ioctl that is resistant to this bug, but future ioctls
may not be.
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | psmq-common.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/psmq-common.h b/psmq-common.h index 63e70f3..bdf0b14 100644 --- a/psmq-common.h +++ b/psmq-common.h @@ -43,9 +43,16 @@ * will calculate number of bytes that are actual usefull and that * should be transfered over. Note: m argument, must be validated, * that is, data[] must have at least on null termination (topic) - * or paylen must be 0 and data[0] = '\0'. */ + * or paylen must be 0 and data[0] = '\0'. + * + * only exception from the rule is ioctl control message, since + * it does not transport topic but only custom binary data, we + * cannot run strlen() on this and simply use paylen as length + * of payload */ #define psmq_real_msg_size(m) (sizeof((m).paylen) + sizeof((m).ctrl) + \ - strlen((m).data) + 1 + (m).paylen) + ((m).ctrl.cmd == PSMQ_CTRL_CMD_IOCTL ? 0 : (strlen((m).data) + 1)) + \ + (m).paylen) + void psmq_ms_to_tp(size_t ms, struct timespec *tp); |