0001-Integer-overflows.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Fix integer overflows. Will not work on compilers with unsigned char
  2. as the default.
  3. Fetched from: https://sources.debian.org/patches/libb64/1.2-5/
  4. Combined "integer overflows.diff" and "off by one.diff" and adapted
  5. for version 1.2.1.
  6. Signed-off-by: Mikael Eliasson <mikael@robomagi.com>
  7. diff --git a/src/cdecode.c b/src/cdecode.c
  8. index a6c0a42..45da4e1 100644
  9. --- a/src/cdecode.c
  10. +++ b/src/cdecode.c
  11. @@ -9,10 +9,11 @@ For details, see http://sourceforge.net/projects/libb64
  12. int base64_decode_value(char value_in)
  13. {
  14. - static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
  15. + static const signed char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
  16. static const char decoding_size = sizeof(decoding);
  17. + if (value_in < 43) return -1;
  18. value_in -= 43;
  19. - if (value_in < 0 || value_in >= decoding_size) return -1;
  20. + if (value_in >= decoding_size) return -1;
  21. return decoding[(int)value_in];
  22. }
  23. @@ -26,7 +27,7 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
  24. {
  25. const char* codechar = code_in;
  26. char* plainchar = plaintext_out;
  27. - char fragment;
  28. + int fragment;
  29. *plainchar = state_in->plainchar;
  30. @@ -42,7 +43,7 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
  31. state_in->plainchar = *plainchar;
  32. return plainchar - plaintext_out;
  33. }
  34. - fragment = (char)base64_decode_value(*codechar++);
  35. + fragment = base64_decode_value(*codechar++);
  36. } while (fragment < 0);
  37. *plainchar = (fragment & 0x03f) << 2;
  38. case step_b:
  39. @@ -53,7 +54,7 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
  40. state_in->plainchar = *plainchar;
  41. return plainchar - plaintext_out;
  42. }
  43. - fragment = (char)base64_decode_value(*codechar++);
  44. + fragment = base64_decode_value(*codechar++);
  45. } while (fragment < 0);
  46. *plainchar++ |= (fragment & 0x030) >> 4;
  47. *plainchar = (fragment & 0x00f) << 4;
  48. @@ -65,7 +66,7 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
  49. state_in->plainchar = *plainchar;
  50. return plainchar - plaintext_out;
  51. }
  52. - fragment = (char)base64_decode_value(*codechar++);
  53. + fragment = base64_decode_value(*codechar++);
  54. } while (fragment < 0);
  55. *plainchar++ |= (fragment & 0x03c) >> 2;
  56. *plainchar = (fragment & 0x003) << 6;
  57. @@ -77,7 +78,7 @@ int base64_decode_block(const char* code_in, const int length_in, char* plaintex
  58. state_in->plainchar = *plainchar;
  59. return plainchar - plaintext_out;
  60. }
  61. - fragment = (char)base64_decode_value(*codechar++);
  62. + fragment = base64_decode_value(*codechar++);
  63. } while (fragment < 0);
  64. *plainchar++ |= (fragment & 0x03f);
  65. }