-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. is OtaAppCallback allowed to be NULL? |
||||||||
|
@@ -3113,26 +3110,36 @@ OtaErr_t OTA_Init( OtaAppBuffer_t * pOtaBuffer, | |||||||
*/ | ||||||||
( void ) otaAgent.pOtaInterface->os.event.init( NULL ); | ||||||||
|
||||||||
if( pThingName == NULL ) | ||||||||
if( pOtaBuffer == 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
else | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
{ | ||||||||
uint32_t strLength = ( uint32_t ) ( strlen( ( const char * ) pThingName ) ); | ||||||||
/* Initialize application buffers. */ | ||||||||
initializeAppBuffers( pOtaBuffer ); | ||||||||
|
||||||||
if( strLength <= otaconfigMAX_THINGNAME_LEN ) | ||||||||
if( pThingName == NULL ) | ||||||||
{ | ||||||||
/* | ||||||||
* Store the Thing name to be used for topics later. Include zero terminator | ||||||||
* when saving the Thing name. | ||||||||
*/ | ||||||||
( 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
LogError messages don't include an \r\n in the rest of this file. |
||||||||
} | ||||||||
else | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||
{ | ||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The signature of this function should be updated from:
to
if pThingName is indeed a null-terminated string. |
||||||||
|
||||||||
if( strLength <= otaconfigMAX_THINGNAME_LEN ) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be simplified to
|
||||||||
{ | ||||||||
/* | ||||||||
* Store the Thing name to be used for topics later. Include zero terminator | ||||||||
* when saving the Thing name. | ||||||||
*/ | ||||||||
( void ) memcpy( otaAgent.pThingName, pThingName, strLength + 1UL ); | ||||||||
returnStatus = OtaErrNone; | ||||||||
} | ||||||||
else | ||||||||
{ | ||||||||
LogError( ( "Error: Thing name is too long.\r\n" ) ); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -972,6 +972,17 @@ void test_OTA_InitNullAppBuffers() | |
TEST_ASSERT_EQUAL( OtaAgentStateInit, OTA_GetState() ); | ||
} | ||
|
||
void test_OTA_InitNullOtaAppPointer() | ||
{ | ||
OtaAppBuffer_t * otaAppBuffer = NULL; | ||
|
||
OTA_Init( otaAppBuffer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Based on the current implementation of the function |
||
&otaInterfaces, | ||
( const uint8_t * ) pOtaDefaultClientId, | ||
mockAppCallback ); | ||
TEST_ASSERT_EQUAL( OtaAgentStateStopped, OTA_GetState() ); | ||
} | ||
|
||
void test_OTA_InitZeroAppBufferSizes() | ||
{ | ||
/* Test for having valid pointers with zero sizes. */ | ||
|
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?