From 681fff9f942dd7adbca209eeca24d70c4ee0adf8 Mon Sep 17 00:00:00 2001 From: CampbellWray Date: Tue, 18 Apr 2017 16:25:58 +1200 Subject: [PATCH] Coap fixes (#1606) * Fixes segmentation fault in POSIX version by removing coap message initialisation with NULL header * Alters API so that there will be no attempt to create messages with NULL header --- src/cli/cli_coap.cpp | 2 +- src/core/api/coap_api.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cli/cli_coap.cpp b/src/cli/cli_coap.cpp index 3c118aa26..a6ba7bc8f 100644 --- a/src/cli/cli_coap.cpp +++ b/src/cli/cli_coap.cpp @@ -260,7 +260,7 @@ exit: ThreadError Coap::ProcessClient(int argc, char *argv[]) { ThreadError error = kThreadError_None; - otMessage *message = otCoapNewMessage(sInstance, NULL); + otMessage *message = NULL; otMessageInfo messageInfo; otCoapHeader header; diff --git a/src/core/api/coap_api.cpp b/src/core/api/coap_api.cpp index d54c9fe35..2ea2dff84 100644 --- a/src/core/api/coap_api.cpp +++ b/src/core/api/coap_api.cpp @@ -126,7 +126,11 @@ const otCoapOption *otCoapHeaderGetNextOption(otCoapHeader *aHeader) otMessage *otCoapNewMessage(otInstance *aInstance, const otCoapHeader *aHeader) { - return aInstance->mThreadNetif.GetCoapClient().NewMessage(*(static_cast(aHeader))); + Message *message; + VerifyOrExit(aHeader != NULL, message = NULL); + message = aInstance->mThreadNetif.GetCoapClient().NewMessage(*(static_cast(aHeader))); +exit: + return message; } ThreadError otCoapSendRequest(otInstance *aInstance, otMessage *aMessage, const otMessageInfo *aMessageInfo,