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

Fix overflow in skipOneHexEscape() #100

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/core_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static bool skipOneHexEscape( const char * buf,

i = *start;
#define HEX_ESCAPE_LENGTH ( 6U ) /* e.g., \u1234 */
end = i + HEX_ESCAPE_LENGTH;
end = ( i <= ( SIZE_MAX - HEX_ESCAPE_LENGTH ) ) ? ( i + HEX_ESCAPE_LENGTH ) : SIZE_MAX;
dan4thewin marked this conversation as resolved.
Show resolved Hide resolved

if( ( end < max ) && ( buf[ i ] == '\\' ) && ( buf[ i + 1U ] == 'u' ) )
{
Expand Down
20 changes: 12 additions & 8 deletions source/include/stdint.readme
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ typedef unsigned long uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;

#define INT8_MAX ( ( signed char ) 127 )
#define UINT8_MAX ( ( unsigned char ) 255 )
#define INT16_MAX ( ( short ) 32767 )
#define UINT16_MAX ( ( unsigned short ) 65535 )
#define INT32_MAX 2147483647L
#define UINT32_MAX 4294967295UL
#define INT64_MAX 9223372036854775807LL
#define UINT64_MAX 18446744073709551615ULL
#define INT8_MAX ( ( signed char ) 127 )
#define UINT8_MAX ( ( unsigned char ) 255 )
#define INT16_MAX ( ( short ) 32767 )
#define UINT16_MAX ( ( unsigned short ) 65535 )
#define INT32_MAX 2147483647L
#define UINT32_MAX 4294967295UL
#define INT64_MAX 9223372036854775807LL
#define UINT64_MAX 18446744073709551615ULL

#ifndef SIZE_MAX
dan4thewin marked this conversation as resolved.
Show resolved Hide resolved
#define SIZE_MAX ( ( size_t ) -1 )
dan4thewin marked this conversation as resolved.
Show resolved Hide resolved
#endif

#endif /* _STDINT_H */
13 changes: 13 additions & 0 deletions test/unit-test/core_json_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1871,3 +1871,16 @@ void test_JSON_unreached( void )
iterate( buf, max, &start, &next, &key, &keyLength, &value, &valueLength ) );
}
}

/**
* @brief Test overflows.
*/
void test_JSON_overflows( void )
{
char buf[] = UNICODE_ESCAPE_SEQUENCES_BMP;
size_t start;
uint16_t u;

start = SIZE_MAX;
TEST_ASSERT_EQUAL( false, skipOneHexEscape( buf, &start, SIZE_MAX, &u ) );
}