aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-01-09 18:04:29 +0000
committerBart Polot <bart@net.in.tum.de>2015-01-09 18:04:29 +0000
commiteb1351b3896ce06f8f6f78c3c317191fb44c36c9 (patch)
treeaaae2c040aa211889980d91b87efd7f1152281ef /src/cadet
parente3fa79f963ecb116c549720531684d81e22a6ba1 (diff)
downloadgnunet-eb1351b3896ce06f8f6f78c3c317191fb44c36c9.tar.gz
gnunet-eb1351b3896ce06f8f6f78c3c317191fb44c36c9.zip
- more size checks
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/gnunet-service-cadet_local.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c
index 5fe160bdc..03fec52c1 100644
--- a/src/cadet/gnunet-service-cadet_local.c
+++ b/src/cadet/gnunet-service-cadet_local.c
@@ -471,14 +471,19 @@ static void
471handle_data (void *cls, struct GNUNET_SERVER_Client *client, 471handle_data (void *cls, struct GNUNET_SERVER_Client *client,
472 const struct GNUNET_MessageHeader *message) 472 const struct GNUNET_MessageHeader *message)
473{ 473{
474 const struct GNUNET_MessageHeader *payload;
474 struct GNUNET_CADET_LocalData *msg; 475 struct GNUNET_CADET_LocalData *msg;
475 struct CadetClient *c; 476 struct CadetClient *c;
476 struct CadetChannel *ch; 477 struct CadetChannel *ch;
477 CADET_ChannelNumber chid; 478 CADET_ChannelNumber chid;
478 size_t size; 479 size_t message_size;
480 size_t payload_size;
481 size_t payload_claimed_size;
479 int fwd; 482 int fwd;
480 483
481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got data from a client!\n"); 484 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
485 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
486 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got data from a client\n");
482 487
483 /* Sanity check for client registration */ 488 /* Sanity check for client registration */
484 if (NULL == (c = GML_client_get (client))) 489 if (NULL == (c = GML_client_get (client)))
@@ -487,22 +492,36 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
487 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 492 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
488 return; 493 return;
489 } 494 }
490 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
491
492 msg = (struct GNUNET_CADET_LocalData *) message;
493 495
494 /* Sanity check for message size */ 496 /* Sanity check for message size */
495 size = ntohs (message->size) - sizeof (struct GNUNET_CADET_LocalData); 497 message_size = ntohs (message->size);
496 if (sizeof (struct GNUNET_MessageHeader) > size) 498 if (sizeof (struct GNUNET_CADET_LocalData)
499 + sizeof (struct GNUNET_MessageHeader) > message_size)
497 { 500 {
498 GNUNET_break (0); 501 GNUNET_break (0);
499 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 502 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
500 return; 503 return;
501 } 504 }
505 payload_size = message_size - sizeof (struct GNUNET_CADET_LocalData);
506 msg = (struct GNUNET_CADET_LocalData *) message;
507 payload = (struct GNUNET_MessageHeader *) &msg[1];
508 payload_claimed_size = ntohs (payload->size);
509 if (sizeof (struct GNUNET_MessageHeader) > payload_claimed_size
510 || GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < payload_claimed_size
511 || payload_claimed_size > payload_size)
512 {
513 LOG (GNUNET_ERROR_TYPE_WARNING,
514 "client claims to send %u bytes in %u payload\n",
515 payload_claimed_size, payload_size);
516 GNUNET_break (0);
517 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
518 return;
519 }
502 520
503 /* Channel exists? */
504 chid = ntohl (msg->id); 521 chid = ntohl (msg->id);
505 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid); 522 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
523
524 /* Channel exists? */
506 fwd = chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 525 fwd = chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV;
507 ch = GML_channel_get (c, chid); 526 ch = GML_channel_get (c, chid);
508 if (NULL == ch) 527 if (NULL == ch)
@@ -514,9 +533,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
514 return; 533 return;
515 } 534 }
516 535
517 if (GNUNET_OK != 536 if (GNUNET_OK != GCCH_handle_local_data (ch, c, fwd, payload, payload_size))
518 GCCH_handle_local_data (ch, c,
519 (struct GNUNET_MessageHeader *)&msg[1], fwd))
520 { 537 {
521 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 538 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
522 return; 539 return;