Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Slight hardening of Message.h

  • Loading branch information...
commit a91e1cbab6e85655d0707b93262342f9521caf29 1 parent f3fef9a
Caleb James DeLisle authored
View
2  admin/angel/Angel.c
@@ -55,7 +55,7 @@ static void handleMessageForAngel(struct Message* message, struct AngelContext*
{
Log_debug(context->logger, "Got message for angel with content [%s]", message->bytes);
char* angelExit = "d1:q10:Angel_exite";
- if (message->length == strlen(angelExit)
+ if (message->length == (int32_t)strlen(angelExit)
&& !Bits_memcmp((char*)message->bytes, angelExit, message->length))
{
Log_info(context->logger, "Got request to exit");
View
4 crypto/CryptoAuth.c
@@ -388,8 +388,6 @@ static uint8_t genReverseHandshake(struct Message* message,
static uint8_t encryptHandshake(struct Message* message, struct CryptoAuth_Wrapper* wrapper)
{
- Assert_true(message->padding >= sizeof(union Headers_CryptoAuth) || !"not enough padding");
-
Message_shift(message, sizeof(union Headers_CryptoAuth));
union Headers_CryptoAuth* header = (union Headers_CryptoAuth*) message->bytes;
@@ -665,7 +663,7 @@ static uint8_t decryptHandshake(struct CryptoAuth_Wrapper* wrapper,
struct Message* message,
union Headers_CryptoAuth* header)
{
- if (message->length < sizeof(union Headers_CryptoAuth)) {
+ if (message->length < Headers_CryptoAuth_SIZE) {
Log_debug(wrapper->context->logger, "Dropped runt packet\n");
return Error_UNDERSIZE_MESSAGE;
}
View
2  switch/SwitchCore.c
@@ -152,7 +152,7 @@ static uint8_t receiveMessage(struct Message* message, struct Interface* iface)
return Error_NONE;
}
- if (message->length < sizeof(struct Headers_SwitchHeader)) {
+ if (message->length < Headers_SwitchHeader_SIZE) {
Log_debug(sourceIf->core->logger, "Dropped runt packet.");
return Error_NONE;
}
View
2  tunnel/test/IpTunnel_test.c
@@ -63,7 +63,7 @@ uint8_t responseWithIpCallback(struct Message* message, struct Interface* iface)
"e"
"4:txid" "4:abcd"
"e";
- Assert_always(message->length == strlen(expectedResponse));
+ Assert_always(message->length == (int32_t) strlen(expectedResponse));
Assert_always(!Bits_memcmp(message->bytes, expectedResponse, message->length));
called = 1;
return 0;
View
15 wire/Message.h
@@ -25,10 +25,10 @@
struct Message
{
/** The length of the message. */
- uint16_t length;
+ int32_t length;
/** The number of bytes of padding BEFORE where bytes begins. */
- uint16_t padding;
+ int32_t padding;
/** The content. */
uint8_t* bytes;
@@ -76,17 +76,16 @@ static inline void Message_copyOver(struct Message* output,
*/
static inline bool Message_shift(struct Message* toShift, int32_t amount)
{
- Assert_true(toShift->padding >= amount);
- Assert_true((amount >= 0) ? (((int32_t)UINT16_MAX) - toShift->length >= amount)
- : (((int32_t)toShift->length) >= -amount));
- Assert_true(toShift->length < 60000);
+ if (amount > 0) {
+ Assert_true(toShift->padding >= amount);
+ } else {
+ Assert_true(toShift->length >= (-amount));
+ }
toShift->length += amount;
toShift->bytes -= amount;
toShift->padding -= amount;
- Assert_true(toShift->length < 60000);
-
return true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.