0005-ID-480-Call-EVP_CIPHER_CTX_free-instead-of-EVP_CIPHE.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. From d9d6e0bff831da03f4448f0cdb82fc3d143662c8 Mon Sep 17 00:00:00 2001
  2. From: Holger Liebig <holger.liebig@ts.fujitsu.com>
  3. Date: Tue, 4 Apr 2017 20:43:05 +0200
  4. Subject: [PATCH] ID:480 - Call EVP_CIPHER_CTX_free() instead of
  5. EVP_CIPHER_CTX_cleanup()
  6. Call EVP_CIPHER_CTX_free() instead of EVP_CIPHER_CTX_cleanup() to fix memory
  7. leak.
  8. Upstream: https://github.com/ipmitool/ipmitool/commit/1664902525a1c3771b4d8b3ccab7ea1ba6b2bdd1
  9. Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
  10. ---
  11. src/plugins/lanplus/lanplus_crypt_impl.c | 44 +++++++++++++++++---------------
  12. 1 file changed, 23 insertions(+), 21 deletions(-)
  13. diff --git a/src/plugins/lanplus/lanplus_crypt_impl.c b/src/plugins/lanplus/lanplus_crypt_impl.c
  14. index 0e330c1..9652a5e 100644
  15. --- a/src/plugins/lanplus/lanplus_crypt_impl.c
  16. +++ b/src/plugins/lanplus/lanplus_crypt_impl.c
  17. @@ -165,13 +165,6 @@ lanplus_encrypt_aes_cbc_128(const uint8_t * iv,
  18. uint32_t * bytes_written)
  19. {
  20. EVP_CIPHER_CTX *ctx = NULL;
  21. - ctx = EVP_CIPHER_CTX_new();
  22. - if (ctx == NULL) {
  23. - *bytes_written = 0;
  24. - return;
  25. - }
  26. - EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
  27. - EVP_CIPHER_CTX_set_padding(ctx, 0);
  28. *bytes_written = 0;
  29. @@ -185,6 +178,14 @@ lanplus_encrypt_aes_cbc_128(const uint8_t * iv,
  30. printbuf(input, input_length, "encrypting this data");
  31. }
  32. + ctx = EVP_CIPHER_CTX_new();
  33. + if (ctx == NULL) {
  34. + lprintf(LOG_DEBUG, "ERROR: EVP_CIPHER_CTX_new() failed");
  35. + return;
  36. + }
  37. + EVP_CIPHER_CTX_init(ctx);
  38. + EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
  39. + EVP_CIPHER_CTX_set_padding(ctx, 0);
  40. /*
  41. * The default implementation adds a whole block of padding if the input
  42. @@ -198,7 +199,6 @@ lanplus_encrypt_aes_cbc_128(const uint8_t * iv,
  43. {
  44. /* Error */
  45. *bytes_written = 0;
  46. - return;
  47. }
  48. else
  49. {
  50. @@ -206,16 +206,17 @@ lanplus_encrypt_aes_cbc_128(const uint8_t * iv,
  51. if(!EVP_EncryptFinal_ex(ctx, output + *bytes_written, (int *)&tmplen))
  52. {
  53. + /* Error */
  54. *bytes_written = 0;
  55. - return; /* Error */
  56. }
  57. else
  58. {
  59. /* Success */
  60. *bytes_written += tmplen;
  61. - EVP_CIPHER_CTX_cleanup(ctx);
  62. }
  63. }
  64. + /* performs cleanup and free */
  65. + EVP_CIPHER_CTX_free(ctx);
  66. }
  67. @@ -243,13 +244,6 @@ lanplus_decrypt_aes_cbc_128(const uint8_t * iv,
  68. uint32_t * bytes_written)
  69. {
  70. EVP_CIPHER_CTX *ctx = NULL;
  71. - ctx = EVP_CIPHER_CTX_new();
  72. - if (ctx == NULL) {
  73. - *bytes_written = 0;
  74. - return;
  75. - }
  76. - EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
  77. - EVP_CIPHER_CTX_set_padding(ctx, 0);
  78. if (verbose >= 5)
  79. {
  80. @@ -258,12 +252,20 @@ lanplus_decrypt_aes_cbc_128(const uint8_t * iv,
  81. printbuf(input, input_length, "decrypting this data");
  82. }
  83. -
  84. *bytes_written = 0;
  85. if (input_length == 0)
  86. return;
  87. + ctx = EVP_CIPHER_CTX_new();
  88. + if (ctx == NULL) {
  89. + lprintf(LOG_DEBUG, "ERROR: EVP_CIPHER_CTX_new() failed");
  90. + return;
  91. + }
  92. + EVP_CIPHER_CTX_init(ctx);
  93. + EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
  94. + EVP_CIPHER_CTX_set_padding(ctx, 0);
  95. +
  96. /*
  97. * The default implementation adds a whole block of padding if the input
  98. * data is perfectly aligned. We would like to keep that from happening.
  99. @@ -277,7 +279,6 @@ lanplus_decrypt_aes_cbc_128(const uint8_t * iv,
  100. /* Error */
  101. lprintf(LOG_DEBUG, "ERROR: decrypt update failed");
  102. *bytes_written = 0;
  103. - return;
  104. }
  105. else
  106. {
  107. @@ -285,20 +286,21 @@ lanplus_decrypt_aes_cbc_128(const uint8_t * iv,
  108. if (!EVP_DecryptFinal_ex(ctx, output + *bytes_written, (int *)&tmplen))
  109. {
  110. + /* Error */
  111. char buffer[1000];
  112. ERR_error_string(ERR_get_error(), buffer);
  113. lprintf(LOG_DEBUG, "the ERR error %s", buffer);
  114. lprintf(LOG_DEBUG, "ERROR: decrypt final failed");
  115. *bytes_written = 0;
  116. - return; /* Error */
  117. }
  118. else
  119. {
  120. /* Success */
  121. *bytes_written += tmplen;
  122. - EVP_CIPHER_CTX_cleanup(ctx);
  123. }
  124. }
  125. + /* performs cleanup and free */
  126. + EVP_CIPHER_CTX_free(ctx);
  127. if (verbose >= 5)
  128. {
  129. --
  130. 1.9.1