Skip to content
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

Format Date Header for ISO8601 Compliance #4

Merged
merged 15 commits into from
Apr 23, 2021
Prev Previous commit
Next Next commit
Add dateLen check
  • Loading branch information
sukhmanm committed Mar 20, 2021
commit 6672462f10a93d045e7f27f0695721651a76cc53
1 change: 1 addition & 0 deletions source/include/sigv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

/**< Length of the date header in ISO 8601 format. */
#define SIGV4_ISO_STRING_LEN 16U
#define SIGV4_EXPECTED_DATE_LEN 20U
sukhmanm marked this conversation as resolved.
Show resolved Hide resolved
/** @}*/

/**
Expand Down
17 changes: 10 additions & 7 deletions source/sigv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ SigV4Status_t SigV4_AwsIotDateToIso8601( const char * pDate,
{
LogError( ( "Parameter check failed: pDate is NULL." ) );
}
/* Check validity of the date header size provided. */
else if( dateLen == 0U )
{
LogError( ( "Parameter check failed: dateLen must be greater than 0." ) );
}
else if( pDateISO8601 == NULL )
{
LogError( ( "Parameter check failed: pDateISO8601 is NULL." ) );
}

/* Check that the buffer provided is large enough for the formatted output
/* Check that the date buffer provided is not shorter than the expected
* input format. */
else if( dateLen < SIGV4_EXPECTED_DATE_LEN + 1 )
sukhmanm marked this conversation as resolved.
Show resolved Hide resolved
{
LogError( ( "Parameter check failed: dateLen must be at least %u.",
SIGV4_EXPECTED_DATE_LEN + 1 ) );
}

/* Check that the output buffer provided is large enough for the formatted
* string. */
else if( dateISO8601Len < SIV4_ISO_STRING_LEN + 1 )
{
Expand All @@ -77,7 +80,7 @@ SigV4Status_t SigV4_AwsIotDateToIso8601( const char * pDate,
&dateInfo.tm_mday,
&dateInfo.tm_hour,
&dateInfo.tm_min,
&dateInfo.tm_sec ) != SIV4_ISO_STRING_LEN - 10U )
&dateInfo.tm_sec ) != 6 )
{
LogError( ( "sscanf() failed to parse the date string using the format expected." ) );
returnStatus = SigV4ISOFormattingError;
Expand Down