Skip to content

Commit 666d8d9

Browse files
authored
Account for pOptionValue alignment in _socketSetSockOptLevelTransport (#208)
* Fix _socketSetSockOptLevelTransport alignment issues Copy value rather than casting to avoid pointer alignment issues. Other changes include: * Fix unit tests failing build * Update link verifier to skip certain URLs
1 parent 5d76e3b commit 666d8d9

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

.github/allowed_urls.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https://www.u-blox.com/en/product/sara-r4-series
2+
https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1515

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ jobs:
138138
env:
139139
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140140
uses: FreeRTOS/CI-CD-Github-Actions/link-verifier@main
141+
with:
142+
allowlist-file: '.github/allowed_urls.txt'
141143

142144
verify-manifest:
143145
runs-on: ubuntu-latest

MISRA.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ _Ref 10.8.1_
7575
and isdigit. We do not have control over these so we are suppressing these
7676
violations.
7777

78-
#### Rule 11.3
79-
80-
_Ref 11.3.1_
81-
82-
- MISRA C-2012 Rule 11.3 does not allow casting of a pointer to different object
83-
types. We are passing in a length variable which is then checked to determine
84-
what to cast this value to. As such we are not worried about the chance of
85-
misaligned access when using the cast variable.
86-
8778
#### Rule 21.6
8879

8980
_Ref 21.6.1_

source/cellular_common_api.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,12 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
6767
uint32_t optionValueLength )
6868
{
6969
CellularError_t cellularStatus = CELLULAR_SUCCESS;
70-
const uint32_t * pTimeoutMs = NULL;
7170

7271
if( option == CELLULAR_SOCKET_OPTION_SEND_TIMEOUT )
7372
{
7473
if( optionValueLength == sizeof( uint32_t ) )
7574
{
76-
/* MISRA Ref 11.3 [Misaligned access] */
77-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
78-
/* coverity[misra_c_2012_rule_11_3_violation] */
79-
pTimeoutMs = ( const uint32_t * ) pOptionValue;
80-
socketHandle->sendTimeoutMs = *pTimeoutMs;
75+
( void ) memcpy( &( socketHandle->sendTimeoutMs ), pOptionValue, sizeof( uint32_t ) );
8176
}
8277
else
8378
{
@@ -88,11 +83,7 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
8883
{
8984
if( optionValueLength == sizeof( uint32_t ) )
9085
{
91-
/* MISRA Ref 11.3 [Misaligned access] */
92-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
93-
/* coverity[misra_c_2012_rule_11_3_violation] */
94-
pTimeoutMs = ( const uint32_t * ) pOptionValue;
95-
socketHandle->recvTimeoutMs = *pTimeoutMs;
86+
( void ) memcpy( &( socketHandle->recvTimeoutMs ), pOptionValue, sizeof( uint32_t ) );
9687
}
9788
else
9889
{
@@ -116,10 +107,7 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o
116107
{
117108
if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) )
118109
{
119-
/* MISRA Ref 11.3 [Misaligned access] */
120-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#rule-113 */
121-
/* coverity[misra_c_2012_rule_11_3_violation] */
122-
socketHandle->localPort = *( ( uint16_t * ) pOptionValue );
110+
( void ) memcpy( &( socketHandle->localPort ), pOptionValue, sizeof( uint16_t ) );
123111
}
124112
else
125113
{

test/unit-test/cellular_pkthandler_utest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CellularAtParseTokenMap_t CellularUrcHandlerTable[] =
8686
{ "RDY", cellularAtParseTokenHandler },
8787
{ "RDY", cellularAtParseTokenHandler }
8888
};
89-
const uint32_t CellularUrcHandlerTableSize = sizeof( CellularUrcHandlerTable ) / sizeof( CellularAtParseTokenMap_t );
89+
#define CellularUrcHandlerTableSize ( sizeof( CellularUrcHandlerTable ) / sizeof( CellularAtParseTokenMap_t ) )
9090

9191
CellularAtParseTokenMap_t CellularUrcHandlerTableWoParseFunc[] =
9292
{
@@ -101,7 +101,7 @@ CellularAtParseTokenMap_t CellularUrcHandlerTableWoParseFunc[] =
101101
{ "QSIMSTAT", NULL },
102102
{ "RDY", NULL }
103103
};
104-
const uint32_t CellularUrcHandlerTableWoParseFuncSize = sizeof( CellularUrcHandlerTableWoParseFunc ) / sizeof( CellularAtParseTokenMap_t );
104+
#define CellularUrcHandlerTableWoParseFuncSize ( sizeof( CellularUrcHandlerTableWoParseFunc ) / sizeof( CellularAtParseTokenMap_t ) )
105105

106106
CellularAtParseTokenMap_t CellularUrcHandlerTableSortFailCase[] =
107107
{
@@ -116,7 +116,7 @@ CellularAtParseTokenMap_t CellularUrcHandlerTableSortFailCase[] =
116116
{ "QSIMSTAT", NULL },
117117
{ "RDY", NULL }
118118
};
119-
const uint32_t CellularUrcHandlerTableSortFailCaseSize = sizeof( CellularUrcHandlerTableSortFailCase ) / sizeof( CellularAtParseTokenMap_t );
119+
#define CellularUrcHandlerTableSortFailCaseSize ( sizeof( CellularUrcHandlerTableSortFailCase ) / sizeof( CellularAtParseTokenMap_t ) )
120120

121121
CellularTokenTable_t tokenTable =
122122
{

test/unit-test/cellular_pktio_utest.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,25 @@ CellularAtParseTokenMap_t CellularUrcHandlerTable[] =
162162
{ "QSIMSTAT", NULL },
163163
{ "RDY", NULL }
164164
};
165-
const uint32_t CellularUrcHandlerTableSize = sizeof( CellularUrcHandlerTable ) / sizeof( CellularAtParseTokenMap_t );
165+
#define CellularUrcHandlerTableSize ( sizeof( CellularUrcHandlerTable ) / sizeof( CellularAtParseTokenMap_t ) )
166166

167167
const char * CellularSrcTokenErrorTable[] =
168168
{ "ERROR", "BUSY", "NO CARRIER", "NO ANSWER", "NO DIALTONE", "ABORTED", "+CMS ERROR", "+CME ERROR", "SEND FAIL" };
169-
const uint32_t CellularSrcTokenErrorTableSize = sizeof( CellularSrcTokenErrorTable ) / sizeof( char * );
169+
#define CellularSrcTokenErrorTableSize ( sizeof( CellularSrcTokenErrorTable ) / sizeof( char * ) )
170170

171171
const char * CellularSrcTokenSuccessTable[] =
172172
{ "OK", "CONNECT", "SEND OK", ">" };
173-
const uint32_t CellularSrcTokenSuccessTableSize = sizeof( CellularSrcTokenSuccessTable ) / sizeof( char * );
173+
#define CellularSrcTokenSuccessTableSize ( sizeof( CellularSrcTokenSuccessTable ) / sizeof( char * ) )
174174

175175
const char * CellularUrcTokenWoPrefixTable[] =
176176
{ "NORMAL POWER DOWN", "PSM POWER DOWN", "RDY" };
177177

178-
const uint32_t CellularUrcTokenWoPrefixTableSize = sizeof( CellularUrcTokenWoPrefixTable ) / sizeof( char * );
178+
#define CellularUrcTokenWoPrefixTableSize ( sizeof( CellularUrcTokenWoPrefixTable ) / sizeof( char * ) )
179179

180180
const char * CellularSrcExtraTokenSuccessTable[] =
181181
{ "EXTRA_TOKEN_1", "EXTRA_TOKEN_2", "EXTRA_TOKEN_3" };
182182

183-
const uint32_t CellularSrcExtraTokenSuccessTableSize = sizeof( CellularSrcExtraTokenSuccessTable ) / sizeof( char * );
183+
#define CellularSrcExtraTokenSuccessTableSize ( sizeof( CellularSrcExtraTokenSuccessTable ) / sizeof( char * ) )
184184

185185
CellularTokenTable_t tokenTable =
186186
{

0 commit comments

Comments
 (0)