mirror of
https://github.com/espressif/openthread.git
synced 2026-07-16 17:14:09 +00:00
[cli] add length check for "service add" (#3508)
This commit is contained in:
+12
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user