From dfae5feb8c09c285a7af403f07a18254d0a86ad3 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 26 Sep 2013 14:55:47 +0200 Subject: mmrfc5424addhmac: correctly handle empty structured data --- runtime/msg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'runtime/msg.c') diff --git a/runtime/msg.c b/runtime/msg.c index 18f72086..85f83502 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -4073,10 +4073,14 @@ MsgAddToStructuredData(msg_t *pMsg, uchar *toadd, rs_size_t len) uchar *newptr; rs_size_t newlen; DEFiRet; - newlen = pMsg->lenStrucData + len; + newlen = (pMsg->pszStrucData[0] == '-') ? len : pMsg->lenStrucData + len; CHKmalloc(newptr = (uchar*) realloc(pMsg->pszStrucData, newlen+1)); pMsg->pszStrucData = newptr; - memcpy(pMsg->pszStrucData+pMsg->lenStrucData, toadd, len); + if(pMsg->pszStrucData[0] == '-') { /* empty? */ + memcpy(pMsg->pszStrucData, toadd, len); + } else { + memcpy(pMsg->pszStrucData+pMsg->lenStrucData, toadd, len); + } pMsg->pszStrucData[newlen] = '\0'; pMsg->lenStrucData = newlen; finalize_it: -- cgit v1.2.3