--- libaitmqtt/src/sub.c 2012/04/27 08:12:30 1.1.1.1.2.4 +++ libaitmqtt/src/sub.c 2012/04/27 15:15:12 1.1.1.1.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sub.c,v 1.1.1.1.2.4 2012/04/27 08:12:30 misho Exp $ +* $Id: sub.c,v 1.1.1.1.2.5 2012/04/27 15:15:12 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -322,13 +322,15 @@ mqtt_readSUBSCRIBE(mqtt_msg_t * __restrict buf, u_shor memset(&subs[i], 0, sizeof subs[i]); subs[i].sub_topic.msg_len = ntohs(var->var_sb.val); - subs[i].sub_topic.msg_base = malloc(subs[i].sub_topic.msg_len); + subs[i].sub_topic.msg_base = malloc(subs[i].sub_topic.msg_len + 1); if (!subs[i].sub_topic.msg_base) { LOGERR; mqtt_subFree(subscr); return -1; - } else + } else { memcpy(subs[i].sub_topic.msg_base, var->var_data, subs[i].sub_topic.msg_len); + ((char*) subs[i].sub_topic.msg_base)[subs[i].sub_topic.msg_len] = 0; + } pos += MQTTHDR_VAR_SIZEOF(var); subs[i].sub_ret = *pos; @@ -445,13 +447,15 @@ mqtt_readUNSUBSCRIBE(mqtt_msg_t * __restrict buf, u_sh memset(&subs[i], 0, sizeof subs[i]); subs[i].sub_topic.msg_len = ntohs(var->var_sb.val); - subs[i].sub_topic.msg_base = malloc(subs[i].sub_topic.msg_len); + subs[i].sub_topic.msg_base = malloc(subs[i].sub_topic.msg_len + 1); if (!subs[i].sub_topic.msg_base) { LOGERR; mqtt_subFree(subscr); return -1; - } else + } else { memcpy(subs[i].sub_topic.msg_base, var->var_data, subs[i].sub_topic.msg_len); + ((char*) subs[i].sub_topic.msg_base)[subs[i].sub_topic.msg_len] = 0; + } pos += MQTTHDR_VAR_SIZEOF(var); }