diff options
Diffstat (limited to 'src/psyc/psyc_common.c')
-rw-r--r-- | src/psyc/psyc_common.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/psyc/psyc_common.c b/src/psyc/psyc_common.c index 7368011fc..bf5643ff2 100644 --- a/src/psyc/psyc_common.c +++ b/src/psyc/psyc_common.c | |||
@@ -33,28 +33,33 @@ | |||
33 | * @param data_size Size of @a data. | 33 | * @param data_size Size of @a data. |
34 | * @param data Data. | 34 | * @param data Data. |
35 | * | 35 | * |
36 | * @return GNUNET_YES or GNUNET_NO | 36 | * @return Message type number |
37 | * or GNUNET_NO if the message contains invalid or no parts. | ||
37 | */ | 38 | */ |
38 | int | 39 | uint16_t |
39 | GNUNET_PSYC_check_message_parts (uint16_t data_size, const char *data) | 40 | GNUNET_PSYC_message_last_part (uint16_t data_size, const char *data) |
40 | { | 41 | { |
41 | const struct GNUNET_MessageHeader *pmsg; | 42 | const struct GNUNET_MessageHeader *pmsg; |
43 | uint16_t ptype = GNUNET_NO; | ||
42 | uint16_t psize = 0; | 44 | uint16_t psize = 0; |
43 | uint16_t pos = 0; | 45 | uint16_t pos = 0; |
44 | 46 | ||
45 | for (pos = 0; data_size + pos < data_size; pos += psize) | 47 | for (pos = 0; pos < data_size; pos += psize) |
46 | { | 48 | { |
47 | pmsg = (const struct GNUNET_MessageHeader *) (data + pos); | 49 | pmsg = (const struct GNUNET_MessageHeader *) (data + pos); |
48 | psize = ntohs (pmsg->size); | 50 | psize = ntohs (pmsg->size); |
49 | if (psize < sizeof (*pmsg) || data_size + pos + psize > data_size) | 51 | ptype = ntohs (pmsg->type); |
52 | if (psize < sizeof (*pmsg) || pos + psize > data_size | ||
53 | || ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD | ||
54 | || GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL < ptype) | ||
50 | { | 55 | { |
51 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 56 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
52 | "Invalid message part of type %u and size %u.", | 57 | "Invalid message part of type %u and size %u.\n", |
53 | ntohs (pmsg->type), psize); | 58 | ptype, psize); |
54 | return GNUNET_NO; | 59 | return GNUNET_NO; |
55 | } | 60 | } |
56 | } | 61 | } |
57 | return GNUNET_YES; | 62 | return ptype; |
58 | } | 63 | } |
59 | 64 | ||
60 | 65 | ||
@@ -89,7 +94,8 @@ GNUNET_PSYC_log_message (enum GNUNET_ErrorType kind, | |||
89 | uint16_t name_size = ntohs (mod->name_size); | 94 | uint16_t name_size = ntohs (mod->name_size); |
90 | char oper = ' ' < mod->oper ? mod->oper : ' '; | 95 | char oper = ' ' < mod->oper ? mod->oper : ' '; |
91 | GNUNET_log (kind, "\t%c%.*s\t%.*s\n", oper, name_size, &mod[1], | 96 | GNUNET_log (kind, "\t%c%.*s\t%.*s\n", oper, name_size, &mod[1], |
92 | ntohs (mod->value_size), ((char *) &mod[1]) + name_size + 1); | 97 | size - sizeof (*mod) - name_size - 1, |
98 | ((char *) &mod[1]) + name_size + 1); | ||
93 | break; | 99 | break; |
94 | } | 100 | } |
95 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: | 101 | case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT: |