diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-11-29 22:08:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-11-29 22:08:02 +0100 |
commit | ce327e34da10ef8722f06255f0060d6e4d1866ab (patch) | |
tree | 2dfab668c858c3f8d994d9c7b465a4fb5b82a7a1 /src | |
parent | 333ed5b94540b68b9967885c215b57818f22fb79 (diff) | |
download | gnunet-ce327e34da10ef8722f06255f0060d6e4d1866ab.tar.gz gnunet-ce327e34da10ef8722f06255f0060d6e4d1866ab.zip |
add macro to check 0-terminated string messages, and fix FTBFS
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/ats_api2_transport.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_mq_lib.h | 25 | ||||
-rw-r--r-- | 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 | |||
190 | check_ats_address_suggestion (void *cls, | 190 | check_ats_address_suggestion (void *cls, |
191 | const struct AddressSuggestionMessage *m) | 191 | const struct AddressSuggestionMessage *m) |
192 | { | 192 | { |
193 | // FIXME: check 0-termination! | 193 | (void) cls; |
194 | // FIXME: MQ API should really have a macro for this! | 194 | GNUNET_MQ_check_zero_termination (m); |
195 | return GNUNET_SYSERR; | 195 | return GNUNET_SYSERR; |
196 | } | 196 | } |
197 | 197 | ||
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 | |||
501 | 501 | ||
502 | 502 | ||
503 | /** | 503 | /** |
504 | * Insert code for a "check_" function that verifies that | ||
505 | * a given variable-length message received over the network | ||
506 | * is followed by a 0-terminated string. If the message @a m | ||
507 | * is not followed by a 0-terminated string, an error is logged | ||
508 | * and the function is returned with #GNUNET_NO. | ||
509 | * | ||
510 | * @param an IPC message with proper type to determine | ||
511 | * the size, starting with a `struct GNUNET_MessageHeader` | ||
512 | */ | ||
513 | #define GNUNET_MQ_check_zero_termination(m) \ | ||
514 | { \ | ||
515 | const char *str = (const char *) &m[1]; \ | ||
516 | const struct GNUNET_MessageHeader *hdr = \ | ||
517 | (const struct GNUNET_MessageHeader *) m; \ | ||
518 | uint16_t slen = ntohs (hdr->size) - sizeof (*m); \ | ||
519 | if ( (0 == slen) || \ | ||
520 | (memchr (str, 0, slen) == &str[slen - 1]) ) \ | ||
521 | { \ | ||
522 | GNUNET_break (0); \ | ||
523 | return GNUNET_NO; \ | ||
524 | } \ | ||
525 | } | ||
526 | |||
527 | |||
528 | /** | ||
504 | * Create a new envelope. | 529 | * Create a new envelope. |
505 | * | 530 | * |
506 | * @param mhp message header to store the allocated message header in, can be NULL | 531 | * @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 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "gnunet_nt_lib.h" | ||
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
31 | #include "gnunet_transport_communication_service.h" | 32 | #include "gnunet_transport_communication_service.h" |
32 | 33 | ||