Skip to content

Commit

Permalink
Fix the misra deviations
Browse files Browse the repository at this point in the history
* Fix rule 18.4 deviations. Not using operators with pointer type.
* Suppress rule 20.5 deviations in misra.config to allow use of undef.
  • Loading branch information
Ubuntu committed Feb 22, 2024
1 parent 640dd3f commit 8923a19
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
12 changes: 6 additions & 6 deletions source/core_pki_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ int8_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
pucSig[ 3 ] = 0x21; /* Increment the length of the R value to account for the 0x00 pad. */
pucSig[ 4 ] = 0x0; /* Write the 0x00 pad. */
( void ) memcpy( &pucSig[ 5 ], ucTemp, 32 ); /* Copy the 32-byte R value. */
pucSigPtr = pucSig + 33; /* Increment the pointer to compensate for padded R length. */
pucSigPtr = &pucSig[ 33 ]; /* Increment the pointer to compensate for padded R length. */
}
else
{
pucSig[ 3 ] = 0x20; /* R length with be 32 bytes. */
( void ) memcpy( &pucSig[ 4 ], ucTemp, 32 ); /* Copy 32 bytes of R into the signature buffer. */
pucSigPtr = pucSig + 32; /* Increment the pointer for 32 byte R length. */
pucSigPtr = &pucSig[ 32 ]; /* Increment the pointer for 32 byte R length. */
}

pucSigPtr += 4; /* Increment the pointer to offset the SEQUENCE, LENGTH, R-INTEGER, LENGTH. */
pucSigPtr[ 0 ] = 0x02; /* INTEGER tag for S. */
pucSigPtr += 1; /* Increment over S INTEGER tag. */
pucSigPtr = &pucSigPtr[ 4 ]; /* Increment the pointer to offset the SEQUENCE, LENGTH, R-INTEGER, LENGTH. */
pucSigPtr[ 0 ] = 0x02; /* INTEGER tag for S. */
pucSigPtr = &pucSigPtr[ 1 ]; /* Increment over S INTEGER tag. */

/******************* S Component. ****************/

Expand All @@ -192,7 +192,7 @@ int8_t PKI_pkcs11SignatureTombedTLSSignature( uint8_t * pucSig,
pucSig[ 1 ]++; /* Increment the length of the structure to account for the 0x00 pad. */
pucSigPtr[ 0 ] = 0x21; /* Increment the length of the S value to account for the 0x00 pad. */
pucSigPtr[ 1 ] = 0x00; /* Write the 0x00 pad. */
pucSigPtr += 2; /* pucSigPtr was pointing at the S-length. Increment by 2 to hop over length and 0 padding. */
pucSigPtr = &pucSigPtr[ 2 ]; /* pucSigPtr was pointing at the S-length. Increment by 2 to hop over length and 0 padding. */

( void ) memcpy( pucSigPtr, &ucTemp[ 32 ], 32 ); /* Copy the S value. */
}
Expand Down
63 changes: 32 additions & 31 deletions tools/coverity/misra.config
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
// MISRA C-2012 Rules

{
version : "2.0",
standard : "c2012",
title: "Coverity MISRA Configuration",
deviations : [
// Disable the following rules.
"version" : "2.0",
"standard" : "c2012",
"title": "Coverity MISRA Configuration",
"deviations" : [
{
deviation: "Directive 4.5",
reason: "Allow names that MISRA considers ambiguous (such as enum IOT_MQTT_CONNECT and function IotMqtt_Connect)."
"deviation": "Directive 4.5",
"reason": "Allow names that MISRA considers ambiguous (such as enum IOT_MQTT_CONNECT and function IotMqtt_Connect)."
},
{
deviation: "Directive 4.8",
reason: "Allow inclusion of unused types. Header files for a specific port, which are needed by all files, may define types that are not used by a specific file."
"deviation": "Directive 4.8",
"reason": "Allow inclusion of unused types. Header files for a specific port, which are needed by all files, may define types that are not used by a specific file."
},
{
deviation: "Directive 4.9",
reason: "Allow inclusion of function like macros. Logging is done using function like macros."
"deviation": "Directive 4.9",
"reason": "Allow inclusion of function like macros. Logging is done using function like macros."
},
{
deviation: "Directive 4.12",
reason: "Allow use of malloc. This library uses malloc to create cryptographic objects."
"deviation": "Directive 4.12",
"reason": "Allow use of malloc. This library uses malloc to create cryptographic objects."
},
{
deviation: "Rule 2.3",
reason: "Allow unused types. Library headers may define types intended for the application's use, but not used within the library files."
"deviation": "Rule 2.3",
"reason": "Allow unused types. Library headers may define types intended for the application's use, but not used within the library files."
},
{
deviation: "Rule 2.4",
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
"deviation": "Rule 2.4",
"reason": "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
},
{
deviation: "Rule 2.5",
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
"deviation": "Rule 2.5",
"reason": "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
},
{
deviation: "Rule 3.1",
reason: "Allow nested comments. Documentation blocks contain comments for example code."
"deviation": "Rule 3.1",
"reason": "Allow nested comments. Documentation blocks contain comments for example code."
},
{
deviation: "Rule 8.7",
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
"deviation": "Rule 8.7",
"reason": "API functions are not used by library. They must be externally visible in order to be used by the application."
},
{
deviation: "Rule 8.13",
reason: "The PKCS #11 API is defined by the PKCS #11 header files distributed by OASIS. There are some parameters that could be const qualified in this implementation, but since the API cannot be modified, are not const qualified."
"deviation": "Rule 8.13",
"reason": "The PKCS #11 API is defined by the PKCS #11 header files distributed by OASIS. There are some parameters that could be const qualified in this implementation, but since the API cannot be modified, are not const qualified."
},
{
deviation: "Rule 21.1",
reason: "Allow use of all macro names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
"deviation": "Rule 20.5",
"reason": "Allow use of undef for a workaround to run in windows."
},
{
deviation: "Rule 21.2",
reason: " Allow use of all macro and identifier names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
"deviation": "Rule 21.1",
"reason": "Allow use of all macro names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
},
{
"deviation": "Rule 21.2",
"reason": " Allow use of all macro and identifier names. For compatibility, some macros introduced in C99 are defined for use with C90 compilers."
}
]
}

0 comments on commit 8923a19

Please sign in to comment.