[diag] don't let the client of diag reserve the \0 byte (#6746)

This commit is contained in:
Li Cao
2021-07-14 08:22:00 -07:00
committed by GitHub
parent 7d75fc62e1
commit e573f2cebb
5 changed files with 12 additions and 8 deletions
+6
View File
@@ -54,6 +54,9 @@ extern "C" {
/**
* This function processes a factory diagnostics command line.
*
* The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the
* output buffer.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aArgsLength The number of elements in @p aArgs.
* @param[in] aArgs An array of arguments.
@@ -74,6 +77,9 @@ otError otDiagProcessCmd(otInstance *aInstance,
/**
* This function processes a factory diagnostics command line.
*
* The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the
* output buffer.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aString A NULL-terminated input string.
* @param[out] aOutput The diagnostics execution result.
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (137)
#define OPENTHREAD_API_VERSION (138)
/**
* @addtogroup api-instance
+3
View File
@@ -59,6 +59,9 @@ extern "C" {
/**
* This function processes a factory diagnostics command line.
*
* The output of this function (the content written to @p aOutput) MUST terminate with `\0` and the `\0` is within the
* output buffer.
*
* @param[in] aInstance The OpenThread instance for current request.
* @param[in] aArgsLength The number of arguments in @p aArgs.
* @param[in] aArgs The arguments of diagnostics command line.
+1 -4
View File
@@ -4521,12 +4521,9 @@ otError Interpreter::ProcessDiag(Arg aArgs[])
char output[OPENTHREAD_CONFIG_DIAG_OUTPUT_BUFFER_SIZE];
// all diagnostics related features are processed within diagnostics module
output[0] = '\0';
output[sizeof(output) - 1] = '\0';
Arg::CopyArgsToStringArray(aArgs, args);
error = otDiagProcessCmd(mInstance, Arg::GetArgsLength(aArgs), args, output, sizeof(output) - 1);
error = otDiagProcessCmd(mInstance, Arg::GetArgsLength(aArgs), args, output, sizeof(output));
OutputFormat("%s", output);
+1 -3
View File
@@ -1340,8 +1340,6 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader)
VerifyOrExit(error == OT_ERROR_NONE, error = WriteLastStatusFrame(aHeader, ThreadErrorToSpinelStatus(error)));
output[sizeof(output) - 1] = '\0';
#if OPENTHREAD_MTD || OPENTHREAD_FTD
// TODO do not pass mfg prefix
// skip mfg prefix from wpantund
@@ -1351,7 +1349,7 @@ otError NcpBase::HandlePropertySet_SPINEL_PROP_NEST_STREAM_MFG(uint8_t aHeader)
}
#endif
otDiagProcessCmdLine(mInstance, string, output, sizeof(output) - 1);
otDiagProcessCmdLine(mInstance, string, output, sizeof(output));
// Prepare the response
SuccessOrExit(error = mEncoder.BeginFrame(aHeader, SPINEL_CMD_PROP_VALUE_IS, SPINEL_PROP_NEST_STREAM_MFG));