diff options
Diffstat (limited to 'src/common/protocol.c')
-rw-r--r-- | src/common/protocol.c | 20 |
1 files changed, 18 insertions, 2 deletions
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) |