From 638642f8a3d750d77c501bcd565c05c2f98bbc2d Mon Sep 17 00:00:00 2001 From: lurchi Date: Sun, 7 Jan 2018 18:35:39 +0100 Subject: [PATCH] properly check size of MsgProcRequest --- src/social/gnunet-service-social.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 520df20b9..60f1b348d 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -1392,19 +1392,23 @@ msg_proc_parse (const struct MsgProcRequest *mpreq, const char **method_prefix, struct GNUNET_HashCode *method_hash) { - uint8_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq); + ssize_t method_size = ntohs (mpreq->header.size) - sizeof (*mpreq); uint16_t offset = GNUNET_STRINGS_buffer_tokenize ((const char *) &mpreq[1], method_size, 1, method_prefix); + if (method_size < 0) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "MsgProcRequest has invalid size\n"); + return GNUNET_SYSERR; + } if (0 == offset || offset != method_size || *method_prefix == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "offset = %u, method_size = %u, method_name = %s\n", - offset, method_size, *method_prefix); + "MsgProcRequest contains invalid method\n"); return GNUNET_SYSERR; } - - GNUNET_CRYPTO_hash (*method_prefix, method_size, method_hash); + GNUNET_CRYPTO_hash (*method_prefix, (size_t) method_size, method_hash); *flags = ntohl (mpreq->flags); return GNUNET_OK; } -- 2.25.1