[cli] add length check for "service add" (#3508)

This commit is contained in:
Jonathan Hui
2019-01-25 08:36:06 -08:00
committed by GitHub
parent 993f537a03
commit 249bc59874
+12 -5
View File
@@ -1630,19 +1630,26 @@ void Interpreter::ProcessService(int argc, char *argv[])
if (strcmp(argv[0], "add") == 0)
{
otServiceConfig cfg;
long enterpriseNumber = 0;
long enterpriseNumber;
size_t length;
VerifyOrExit(argc > 3, error = OT_ERROR_INVALID_ARGS);
SuccessOrExit(error = ParseLong(argv[1], enterpriseNumber));
cfg.mEnterpriseNumber = static_cast<uint32_t>(enterpriseNumber);
cfg.mServiceDataLength = static_cast<uint8_t>(strlen(argv[2]));
length = strlen(argv[2]);
VerifyOrExit(length <= sizeof(cfg.mServiceData), error = OT_ERROR_NO_BUFS);
cfg.mServiceDataLength = static_cast<uint8_t>(length);
memcpy(cfg.mServiceData, argv[2], cfg.mServiceDataLength);
cfg.mEnterpriseNumber = static_cast<uint32_t>(enterpriseNumber);
cfg.mServerConfig.mStable = true;
cfg.mServerConfig.mServerDataLength = static_cast<uint8_t>(strlen(argv[3]));
length = strlen(argv[3]);
VerifyOrExit(length <= sizeof(cfg.mServerConfig.mServerData), error = OT_ERROR_NO_BUFS);
cfg.mServerConfig.mServerDataLength = static_cast<uint8_t>(length);
memcpy(cfg.mServerConfig.mServerData, argv[3], cfg.mServerConfig.mServerDataLength);
cfg.mServerConfig.mStable = true;
SuccessOrExit(error = otServerAddService(mInstance, &cfg));
}
else if (strcmp(argv[0], "remove") == 0)