[cli] fix usage of strncpy in coap (#6908)

This commit is contained in:
Jonathan Hui
2021-08-10 18:18:15 -07:00
committed by GitHub
parent a94e88cd50
commit d4005f9d14
2 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -402,8 +402,8 @@ otError Coap::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode)
SuccessOrExit(error = aArgs[0].ParseAsIp6Address(coapDestinationIp));
VerifyOrExit(!aArgs[1].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(aArgs[1].GetLength() < kMaxUriLength, error = OT_ERROR_INVALID_ARGS);
strncpy(coapUri, aArgs[1].GetCString(), sizeof(coapUri) - 1);
VerifyOrExit(aArgs[1].GetLength() < sizeof(coapUri), error = OT_ERROR_INVALID_ARGS);
strcpy(coapUri, aArgs[1].GetCString());
// CoAP-Type
if (!aArgs[2].IsEmpty())
+3 -2
View File
@@ -61,6 +61,7 @@ CoapSecure::CoapSecure(Interpreter &aInterpreter)
memset(&mResource, 0, sizeof(mResource));
memset(&mPsk, 0, sizeof(mPsk));
memset(&mPskId, 0, sizeof(mPskId));
memset(&mUriPath, 0, sizeof(mUriPath));
strncpy(mResourceContent, "0", sizeof(mResourceContent));
mResourceContent[sizeof(mResourceContent) - 1] = '\0';
}
@@ -249,8 +250,8 @@ otError CoapSecure::ProcessRequest(Arg aArgs[], otCoapCode aCoapCode)
#endif
VerifyOrExit(!aArgs[0].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
strncpy(coapUri, aArgs[0].GetCString(), sizeof(coapUri) - 1);
VerifyOrExit(aArgs[0].GetLength() < sizeof(coapUri), error = OT_ERROR_INVALID_ARGS);
strcpy(coapUri, aArgs[0].GetCString());
if (!aArgs[1].IsEmpty())
{