fix-incorrect-EOF-check-in-ssl_context_info.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From d696e7d91e42a190d06760279d2e396392143454 Mon Sep 17 00:00:00 2001
  2. From: Nayna Jain <nayna@linux.ibm.com>
  3. Date: Thu, 13 Aug 2020 19:17:53 +0000
  4. Subject: [PATCH] programs/ssl: Fix incorrect EOF check in ssl_context_info.c
  5. In `read_next_b64_code()`, the result of fgetc() is stored into a char,
  6. but later compared against EOF, which is generally -1. On platforms
  7. where char is unsigned, this generates a compiler warning/error that the
  8. comparison will never be true (causing a build failure). The value will
  9. never match, with the function ultimately bailing with a "Too many bad
  10. symbols are detected" error.
  11. On platforms with signed char, EOF is detected, but a file containing a
  12. 0xFF character will causes a premature end of file exit of the loop.
  13. Fix this by changing the result to an int.
  14. Fixes #3794.
  15. Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
  16. Signed-off-by: David Brown <david.brown@linaro.org>
  17. ---
  18. ChangeLog.d/bugfix_3794.txt | 4 ++++
  19. programs/ssl/ssl_context_info.c | 4 ++--
  20. 2 files changed, 6 insertions(+), 2 deletions(-)
  21. create mode 100644 ChangeLog.d/bugfix_3794.txt
  22. diff --git a/ChangeLog.d/bugfix_3794.txt b/ChangeLog.d/bugfix_3794.txt
  23. new file mode 100644
  24. index 0000000000..a483ea76ae
  25. --- /dev/null
  26. +++ b/ChangeLog.d/bugfix_3794.txt
  27. @@ -0,0 +1,4 @@
  28. +Bugfix
  29. + * Fix handling of EOF against 0xff bytes and on platforms with
  30. + unsigned chars. Fixes a build failure on platforms where char is
  31. + unsigned. Fixes #3794.
  32. diff --git a/programs/ssl/ssl_context_info.c b/programs/ssl/ssl_context_info.c
  33. index df8819a804..d109c1e6f7 100644
  34. --- a/programs/ssl/ssl_context_info.c
  35. +++ b/programs/ssl/ssl_context_info.c
  36. @@ -377,13 +377,13 @@ size_t read_next_b64_code( uint8_t **b64, size_t *max_len )
  37. int valid_balance = 0; /* balance between valid and invalid characters */
  38. size_t len = 0;
  39. char pad = 0;
  40. - char c = 0;
  41. + int c = 0;
  42. while( EOF != c )
  43. {
  44. char c_valid = 0;
  45. - c = (char) fgetc( b64_file );
  46. + c = fgetc( b64_file );
  47. if( pad > 0 )
  48. {