summaryrefslogtreecommitdiff
path: root/src/include/gnunet_mq_lib.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-11-29 22:08:02 +0100
committerChristian Grothoff <christian@grothoff.org>2018-11-29 22:08:02 +0100
commitce327e34da10ef8722f06255f0060d6e4d1866ab (patch)
tree2dfab668c858c3f8d994d9c7b465a4fb5b82a7a1 /src/include/gnunet_mq_lib.h
parent333ed5b94540b68b9967885c215b57818f22fb79 (diff)
add macro to check 0-terminated string messages, and fix FTBFS
Diffstat (limited to 'src/include/gnunet_mq_lib.h')
-rw-r--r--src/include/gnunet_mq_lib.h25
1 files changed, 25 insertions, 0 deletions
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