diff options
-rw-r--r-- | include/protocol.h | 2 | ||||
-rw-r--r-- | src/common/protocol.c | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/include/protocol.h b/include/protocol.h index d8f395d..bf2a943 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -86,7 +86,7 @@ enum tlv_type { */ struct tlv_packet { enum packet_type type; - size_t packet_size; + size_t size; size_t offset; char *data; /* Bytes representing tlv's */ }; diff --git a/src/common/protocol.c b/src/common/protocol.c index a7cb84f..2b4e3bf 100644 --- a/src/common/protocol.c +++ b/src/common/protocol.c @@ -30,6 +30,7 @@ #include "protocol.h" #include "protocol_private.h" #include "net.h" +#include "util.h" #define READ_AS(type, from) (*((type*)(from))) @@ -57,12 +58,27 @@ int push_data(enum tlv_type type) static int push_string(struct tlv_packet *packet, const char *str) { - return 0; + size_t strsize = strlen(str); + int ret = 0; + + if (strsize + packet->offset >= packet->size) { + ret = E_TLV_OVERFLOW; + } else { + memcpy(packet->data, str, strsize); + } + return ret; } static int push_fpi1(struct tlv_packet *packet, const char *num) { - return 0; + int ret = 0; + + if (packet->offset + sizeof(fpi1_t) >= packet->size) { + ret = E_TLV_OVERFLOW; + } else { + memcpy(packet->data, num, sizeof(fpi1_t)); + } + return ret; } static int push_timestamp(struct tlv_packet *packet, const char *data) |