Skip to content

Commit d288e43

Browse files
committed
Fail on message sending if too big
CURA-11103 Previously we would correctly send the message, but be unable to parse it at receiving time. Now we apply a more fail-fast strategy.
1 parent 3c30572 commit d288e43

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/Socket_p.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#define VERSION_MINOR 0
4444

4545
#define ARCUS_SIGNATURE 0x2BAD
46-
#define SIG(n) (((n)&0xffff0000) >> 16)
46+
#define SIG(n) (((n) & 0xffff0000) >> 16)
4747

4848
#define SOCKET_CLOSE 0xf0f0f0f0
4949

@@ -360,7 +360,11 @@ void Socket::Private::sendMessage(const MessagePtr& message)
360360
}
361361

362362
std::string data = message->SerializeAsString();
363-
if (platform_socket.writeBytes(data.size(), data.data()) == -1)
363+
if (data.size() > message_size_maximum)
364+
{
365+
error(ErrorCode::SendFailedError, "Message is too big to be sent");
366+
}
367+
else if (platform_socket.writeBytes(data.size(), data.data()) == -1)
364368
{
365369
error(ErrorCode::SendFailedError, "Could not send message data");
366370
}
@@ -571,4 +575,4 @@ void Socket::Private::checkConnectionState()
571575
}
572576
} // namespace Arcus
573577

574-
#endif // SOCKET_P_H
578+
#endif // SOCKET_P_H

0 commit comments

Comments
 (0)