Skip to content

Commit

Permalink
Print string with length check (aws#493)
Browse files Browse the repository at this point in the history
* Print string with length check

* Use temp buffer to print debug log
  • Loading branch information
ActoryOu authored Aug 9, 2023
1 parent deffbf8 commit 243786d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</tr>
<tr>
<td>ota.c</td>
<td><center>8.6K</center></td>
<td><center>7.7K</center></td>
<td><center>8.7K</center></td>
<td><center>7.8K</center></td>
</tr>
<tr>
<td>ota_interface.c</td>
Expand Down Expand Up @@ -39,7 +39,7 @@
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>12.8K</center></b></td>
<td><b><center>11.6K</center></b></td>
<td><b><center>12.9K</center></b></td>
<td><b><center>11.7K</center></b></td>
</tr>
</table>
14 changes: 13 additions & 1 deletion source/ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,20 @@ static DocParseErr_t parseJSONbyModel( const char * pJson,
uint16_t paramIndex = 0;
const char * pFileParams = NULL;
uint32_t fileParamsLength = 0;
static char cJsonBuffer[ OTA_MAX_JSON_STR_LEN ];

LogDebug( ( "JSON received: %s", pJson ) );
if( messageLength < OTA_MAX_JSON_STR_LEN - 1 )
{
memcpy( cJsonBuffer, pJson, messageLength );
cJsonBuffer[ messageLength + 1 ] = 0;
}
else
{
memcpy( cJsonBuffer, pJson, OTA_MAX_JSON_STR_LEN - 2 );
cJsonBuffer[ OTA_MAX_JSON_STR_LEN - 1 ] = 0;
}

LogDebug( ( "JSON received: %s", cJsonBuffer ) );

/* Fetch the model parameters from the DocModel*/
pModelParam = pDocModel->pBodyDef;
Expand Down

0 comments on commit 243786d

Please sign in to comment.