You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
3.0 KiB

  1. From ab5b4e3acd2b0379e5d8bc95a8d4f83ce5c91fb7 Mon Sep 17 00:00:00 2001
  2. From: Michael Heimpold <mhei@heimpold.de>
  3. Date: Sun, 4 Jun 2017 15:00:33 +0200
  4. Subject: [PATCH] Handle NULL strings gracefully during constant registration
  5. When libcurl is compiled not using e.g. libz or SSL, then a call to
  6. curl_version_info could return NULL in the corresponding fields of
  7. curl_version_info_data.
  8. Passing such NULL pointers down to REGISTER_NS_STRING_CONSTANT results
  9. in a segfault during php startup, so let's check for this special case
  10. and register a NULL constant in this case.
  11. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
  12. ---
  13. src/php_http_client_curl.c | 16 ++++++++++++----
  14. 1 file changed, 12 insertions(+), 4 deletions(-)
  15. diff --git a/src/php_http_client_curl.c b/src/php_http_client_curl.c
  16. index f286324..f07bb8f 100644
  17. --- a/src/php_http_client_curl.c
  18. +++ b/src/php_http_client_curl.c
  19. @@ -2429,6 +2429,14 @@ php_http_client_ops_t *php_http_client_curl_get_ops(void)
  20. return &php_http_client_curl_ops;
  21. }
  22. +#define REGISTER_NS_STRING_OR_NULL_CONSTANT(ns, name, str, flags) \
  23. + do { \
  24. + if ((str) != NULL) { \
  25. + REGISTER_NS_STRING_CONSTANT(ns, name, str, flags); \
  26. + } else { \
  27. + REGISTER_NS_NULL_CONSTANT(ns, name, flags); \
  28. + } \
  29. + } while (0)
  30. PHP_MINIT_FUNCTION(http_client_curl)
  31. {
  32. @@ -2509,12 +2517,12 @@ PHP_MINIT_FUNCTION(http_client_curl)
  33. REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl", "VERSIONS", curl_version(), CONST_CS|CONST_PERSISTENT);
  34. #if CURLVERSION_NOW >= 0
  35. REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "CURL", (char *) info->version, CONST_CS|CONST_PERSISTENT);
  36. - REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "SSL", (char *) info->ssl_version, CONST_CS|CONST_PERSISTENT);
  37. - REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", (char *) info->libz_version, CONST_CS|CONST_PERSISTENT);
  38. + REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "SSL", (char *) info->ssl_version, CONST_CS|CONST_PERSISTENT);
  39. + REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "LIBZ", (char *) info->libz_version, CONST_CS|CONST_PERSISTENT);
  40. # if CURLVERSION_NOW >= 1
  41. - REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "ARES", (char *) info->ares, CONST_CS|CONST_PERSISTENT);
  42. + REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "ARES", (char *) info->ares, CONST_CS|CONST_PERSISTENT);
  43. # if CURLVERSION_NOW >= 2
  44. - REGISTER_NS_STRING_CONSTANT("http\\Client\\Curl\\Versions", "IDN", (char *) info->libidn, CONST_CS|CONST_PERSISTENT);
  45. + REGISTER_NS_STRING_OR_NULL_CONSTANT("http\\Client\\Curl\\Versions", "IDN", (char *) info->libidn, CONST_CS|CONST_PERSISTENT);
  46. # endif
  47. # endif
  48. #endif
  49. --
  50. 2.7.4