Skip to content

Commit

Permalink
programs/ssl: Fixes incorrect EOF check in ssl_context_info.c
Browse files Browse the repository at this point in the history
read_next_b64_code() function, that parses base64 encoded input
doesn't recognize the EOF and returns when "Too many bad symbols
are detected". This issue got identified when gcc complained for
type-limit error during cmake.

This patch fixes the issue by changing the variable type to int
and removing type-cast of fgetc() output to 'char'.

[[email protected]]
The context info test stores the result of `fgetc` in a 'char'.  On
platforms with signed characters, reading a 0xFF byte will result in
this character being -1, triggering an early end of file.

On platforms with an unsigned char, all characters will be valid, but
end of file won't be detected.

Fixes Mbed-TLS#3794.

Signed-off-by: Nayna Jain <[email protected]>
Signed-off-by: David Brown <[email protected]>
  • Loading branch information
naynajain authored and d3zd3z committed Oct 16, 2020
1 parent 8f24a8b commit 25b1f0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.d/bugfix_3794.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix
* Fix handling of EOF against 0xff bytes and on platforms with
unsigned chars. Fixes #3794.
4 changes: 2 additions & 2 deletions programs/ssl/ssl_context_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ size_t read_next_b64_code( uint8_t **b64, size_t *max_len )
int valid_balance = 0; /* balance between valid and invalid characters */
size_t len = 0;
char pad = 0;
char c = 0;
int c = 0;

while( EOF != c )
{
char c_valid = 0;

c = (char) fgetc( b64_file );
c = fgetc( b64_file );

if( pad > 0 )
{
Expand Down

0 comments on commit 25b1f0a

Please sign in to comment.