Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit ec4a537

Browse files
emargolisrobszewczyk
authored andcommitted
Fix Buffer Overflow Vulnerability DumpHandler() Function.
This change addresses CVE security vulnerability: CVE-2019-5038
1 parent c5d1aeb commit ec4a537

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/lib/core/WeaveTLVDebug.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ namespace Debug {
5050
* @a aWriter.
5151
*
5252
* @param[in] aWriter The writer to log the TLV data.
53-
* @param[in] aTabs The indentation for logging the current depth into
53+
* @param[in] aIndent The indentation for logging the current depth into
5454
* the TLV data.
5555
* @param[in] aReader A read-only reference to the TLV reader containing
5656
* the TLV data to log.
5757
* @param[in] aDepth The current depth into the TLV data.
5858
*
5959
*/
60-
static void DumpHandler(DumpWriter aWriter, const char *aTabs, const TLVReader &aReader, size_t aDepth)
60+
static void DumpHandler(DumpWriter aWriter, const char *aIndent, const TLVReader &aReader, size_t aDepth)
6161
{
6262
const TLVType type = aReader.GetType();
6363
const uint64_t tag = aReader.GetTag();
@@ -70,7 +70,10 @@ static void DumpHandler(DumpWriter aWriter, const char *aTabs, const TLVReader &
7070
temp.Init(aReader);
7171
tagControl = static_cast<TLVTagControl>(temp.GetControlByte() & kTLVTagControlMask);
7272

73-
aWriter("%zd %s", aDepth, aTabs);
73+
aWriter("%zd ", aDepth);
74+
75+
for (size_t i = 0; i < aDepth; i++)
76+
aWriter("%s", aIndent);
7477

7578
aWriter("%p, ", temp.GetReadPoint());
7679

@@ -333,8 +336,7 @@ WEAVE_ERROR DumpIterator(DumpWriter aWriter, const TLVReader &aReader)
333336
*/
334337
WEAVE_ERROR DumpHandler(const TLVReader &aReader, size_t aDepth, void *aContext)
335338
{
336-
static const char tabs[] = " ";
337-
char tabbuf[48];
339+
static const char indent[] = " ";
338340
WEAVE_ERROR retval = WEAVE_NO_ERROR;
339341
DumpContext * context;
340342

@@ -344,12 +346,8 @@ WEAVE_ERROR DumpHandler(const TLVReader &aReader, size_t aDepth, void *aContext)
344346

345347
VerifyOrExit(context->mWriter != NULL, retval = WEAVE_ERROR_INVALID_ARGUMENT);
346348

347-
strncpy(tabbuf, tabs, aDepth);
348-
349-
tabbuf[aDepth] = 0;
350-
351349
DumpHandler(context->mWriter,
352-
tabbuf,
350+
indent,
353351
aReader,
354352
aDepth);
355353

0 commit comments

Comments
 (0)