-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add checks for pOtaBuffer to be non_null #402
base: main
Are you sure you want to change the base?
Conversation
} | ||
else | ||
{ | ||
LogError( ( "Error: Thing name is too long.\r\n" ) ); | ||
uint32_t strLength = ( uint32_t ) ( strlen( ( const char * ) pThingName ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of this function should be updated from:
OtaErr_t OTA_Init( OtaAppBuffer_t * pOtaBuffer,
const OtaInterfaces_t * pOtaInterfaces,
const uint8_t * pThingName,
OtaAppCallback_t OtaAppCallback )
to
OtaErr_t OTA_Init( OtaAppBuffer_t * pOtaBuffer,
const OtaInterfaces_t * pOtaInterfaces,
const char * pThingName,
OtaAppCallback_t OtaAppCallback )
if pThingName is indeed a null-terminated string.
LogError( ( "Error: Thing name is too long.\r\n" ) ); | ||
uint32_t strLength = ( uint32_t ) ( strlen( ( const char * ) pThingName ) ); | ||
|
||
if( strLength <= otaconfigMAX_THINGNAME_LEN ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to
if( strnlen( pThingName, otaconfigMAX_THINGNAME_LEN + 1 ) <= otaconfigMAX_THINGNAME_LEN )
{
(void) strncpy( otaAgent.pThingName, pThingName, otaconfigMAX_THINGNAME_LEN );
}
else
{
LogError("...");
returnStatus = xxx;
}
} | ||
else | ||
{ | ||
LogError( ( "Error: Thing name is too long.\r\n" ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't returnStatus be set to a particular value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError( ( "Error: Thing name is too long.\r\n" ) ); | |
LogError( ( "Error: Thing name is too long." ) ); |
*/ | ||
( void ) memcpy( otaAgent.pThingName, pThingName, strLength + 1UL ); | ||
returnStatus = OtaErrNone; | ||
LogError( ( "Error: Thing name is NULL.\r\n" ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError( ( "Error: Thing name is NULL.\r\n" ) ); | |
LogError( ( "Error: Thing name is NULL." ) ); | |
returnStatus = OtaErrInvalidArg; |
LogError messages don't include an \r\n in the rest of this file.
{ | ||
LogError( ( "Error: Thing name is NULL.\r\n" ) ); | ||
LogError( ( "Error: pOtaBuffer is NULL.\r\n" ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LogError( ( "Error: pOtaBuffer is NULL.\r\n" ) ); | |
LogError( ( "Error: pOtaBuffer is NULL." ) ); |
{ | ||
LogError( ( "Error: Thing name is NULL.\r\n" ) ); | ||
LogError( ( "Error: pOtaBuffer is NULL.\r\n" ) ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
returnStatus = OtaErrInvalidArg; | |
} |
{ | ||
LogError( ( "Error: Thing name is NULL.\r\n" ) ); | ||
LogError( ( "Error: pOtaBuffer is NULL.\r\n" ) ); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else | |
if( returnStatus == OtaErrNone ) |
{ | ||
OtaAppBuffer_t * otaAppBuffer = NULL; | ||
|
||
OTA_Init( otaAppBuffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value of OTA_Init should be checked ( Should be OtaErrInvalidArg right? ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the current implementation of the function OTA_Init
only returns two values. If there are no errors during the initialization of the agent then it returns OtaErrNone
and OtaErrUninitialized
otherwise.
*/ | ||
( void ) memcpy( otaAgent.pThingName, pThingName, strLength + 1UL ); | ||
returnStatus = OtaErrNone; | ||
LogError( ( "Error: Thing name is NULL.\r\n" ) ); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be turned into an if / else if / else set of statements to improve readability.
@@ -3094,9 +3094,6 @@ OtaErr_t OTA_Init( OtaAppBuffer_t * pOtaBuffer, | |||
*/ | |||
otaAgent.pOtaInterface = pOtaInterfaces; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is pOtaInterfaces allowed to be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pOtaInterfaces can be NULL. There is a conditional statement in OTA_EventProcessingTask function which checks if the pOtaInterfaces are NULL, if they are then the OTA agent would throws an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return an error if the parameter is invalid?
@@ -3094,9 +3094,6 @@ OtaErr_t OTA_Init( OtaAppBuffer_t * pOtaBuffer, | |||
*/ | |||
otaAgent.pOtaInterface = pOtaInterfaces; | |||
|
|||
/* Initialize application buffers. */ | |||
initializeAppBuffers( pOtaBuffer ); | |||
|
|||
/* Initialize local buffers. */ | |||
initializeLocalBuffers(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is OtaAppCallback allowed to be NULL?
OTA_Init
is a public function and a user can pass NULL value topOtaBuffer
which can result inNULL
pointer de-referencing ininitializeAppBuffers
function.Description
This PR adds checks such that if NULL value is passed to pOtaBuffer then the otaAgent would not run and display error in the logs indicating the
NULL
pointer in pOtaBuffer.Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.