0001-ustream-ssl-skip-writing-pending-data.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From c9b6668215a27f2346d5eedd6f29cc720985b448 Mon Sep 17 00:00:00 2001
  2. From: Jo-Philipp Wich <jo@mein.io>
  3. Date: Wed, 11 Sep 2019 21:09:59 +0200
  4. Subject: [PATCH] ustream-ssl: skip writing pending data if .eof is true after
  5. connect
  6. Check the .eof member of the underlying ustream after the call to
  7. __ustream_ssl_connect() since existing users of the library appear
  8. to set the eof flag as a way to signal connection termination upon
  9. failing certificate verification.
  10. This is a stop-gap measure to address TALOS-2019-0893 but a proper
  11. API redesign is required to give applications proper control over
  12. whether certificate failures are to be ignored or not and the default
  13. implementation without custom callbacks should always terminate on
  14. verification failures.
  15. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  16. ---
  17. ustream-ssl.c | 20 ++++++++++++++++++++
  18. 1 file changed, 20 insertions(+)
  19. diff --git a/ustream-ssl.c b/ustream-ssl.c
  20. index e6b084b..47f66d6 100644
  21. --- a/ustream-ssl.c
  22. +++ b/ustream-ssl.c
  23. @@ -40,6 +40,26 @@ static void ustream_ssl_check_conn(struct ustream_ssl *us)
  24. return;
  25. if (__ustream_ssl_connect(us) == U_SSL_OK) {
  26. +
  27. + /* __ustream_ssl_connect() will also return U_SSL_OK when certificate
  28. + * verification failed!
  29. + *
  30. + * Applications may register a custom .notify_verify_error callback in the
  31. + * struct ustream_ssl which is called upon verification failures, but there
  32. + * is no straight forward way for the callback to terminate the connection
  33. + * initiation right away, e.g. through a true or false return value.
  34. + *
  35. + * Instead, existing implementations appear to set .eof field of the underlying
  36. + * ustream in the hope that this inhibits further operations on the stream.
  37. + *
  38. + * Declare this informal behaviour "official" and check for the state of the
  39. + * .eof member after __ustream_ssl_connect() returned, and do not write the
  40. + * pending data if it is set to true.
  41. + */
  42. +
  43. + if (us->stream.eof)
  44. + return;
  45. +
  46. us->connected = true;
  47. if (us->notify_connected)
  48. us->notify_connected(us);
  49. --
  50. 2.20.1