[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] branch master updated: add macro to check 0-termin
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] branch master updated: add macro to check 0-terminated string messages, and fix FTBFS |
Date: |
Thu, 29 Nov 2018 22:08:07 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new ce327e34d add macro to check 0-terminated string messages, and fix
FTBFS
ce327e34d is described below
commit ce327e34da10ef8722f06255f0060d6e4d1866ab
Author: Christian Grothoff <address@hidden>
AuthorDate: Thu Nov 29 22:08:02 2018 +0100
add macro to check 0-terminated string messages, and fix FTBFS
---
src/ats/ats_api2_transport.c | 4 ++--
src/include/gnunet_mq_lib.h | 25 +++++++++++++++++++++++++
src/transport/gnunet-communicator-unix.c | 1 +
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/ats/ats_api2_transport.c b/src/ats/ats_api2_transport.c
index b8133beea..6add4baf5 100644
--- a/src/ats/ats_api2_transport.c
+++ b/src/ats/ats_api2_transport.c
@@ -190,8 +190,8 @@ static int
check_ats_address_suggestion (void *cls,
const struct AddressSuggestionMessage *m)
{
- // FIXME: check 0-termination!
- // FIXME: MQ API should really have a macro for this!
+ (void) cls;
+ GNUNET_MQ_check_zero_termination (m);
return GNUNET_SYSERR;
}
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index 3d3a74e3b..f5f0fd701 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -501,6 +501,31 @@ struct GNUNET_MQ_MessageHandler
/**
+ * Insert code for a "check_" function that verifies that
+ * a given variable-length message received over the network
+ * is followed by a 0-terminated string. If the message @a m
+ * is not followed by a 0-terminated string, an error is logged
+ * and the function is returned with #GNUNET_NO.
+ *
+ * @param an IPC message with proper type to determine
+ * the size, starting with a `struct GNUNET_MessageHeader`
+ */
+#define GNUNET_MQ_check_zero_termination(m) \
+ { \
+ const char *str = (const char *) &m[1]; \
+ const struct GNUNET_MessageHeader *hdr = \
+ (const struct GNUNET_MessageHeader *) m; \
+ uint16_t slen = ntohs (hdr->size) - sizeof (*m); \
+ if ( (0 == slen) || \
+ (memchr (str, 0, slen) == &str[slen - 1]) ) \
+ { \
+ GNUNET_break (0); \
+ return GNUNET_NO; \
+ } \
+ }
+
+
+/**
* Create a new envelope.
*
* @param mhp message header to store the allocated message header in, can be
NULL
diff --git a/src/transport/gnunet-communicator-unix.c
b/src/transport/gnunet-communicator-unix.c
index 0df3fd45d..552b032dd 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -27,6 +27,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
+#include "gnunet_nt_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_communication_service.h"
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] branch master updated: add macro to check 0-terminated string messages, and fix FTBFS,
gnunet <=