0006-block-Handle-curl-7.55.0-7.85.0-version-changes.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. From 88d4ac032fa3d424fa3f8ac93f4ffd07022c19d6 Mon Sep 17 00:00:00 2001
  2. From: Anton Johansson <anjo@rev.ng>
  3. Date: Mon, 23 Jan 2023 21:14:31 +0100
  4. Subject: [PATCH 6/6] block: Handle curl 7.55.0, 7.85.0 version changes
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. * 7.55.0 deprecates CURLINFO_CONTENT_LENGTH_DOWNLOAD in favour of a *_T
  9. version, which returns curl_off_t instead of a double.
  10. * 7.85.0 deprecates CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS in
  11. favour of *_STR variants, specifying the desired protocols via a
  12. string.
  13. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1440
  14. Signed-off-by: Anton Johansson <anjo@rev.ng>
  15. Message-Id: <20230123201431.23118-1-anjo@rev.ng>
  16. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
  17. Reviewed-by: Kevin Wolf <kwolf@redhat.com>
  18. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  19. ---
  20. block/curl.c | 44 +++++++++++++++++++++++++++++++++++++-------
  21. 1 file changed, 37 insertions(+), 7 deletions(-)
  22. diff --git a/block/curl.c b/block/curl.c
  23. index cba4c4cac7..0b125095e3 100644
  24. --- a/block/curl.c
  25. +++ b/block/curl.c
  26. @@ -37,8 +37,15 @@
  27. // #define DEBUG_VERBOSE
  28. +/* CURL 7.85.0 switches to a string based API for specifying
  29. + * the desired protocols.
  30. + */
  31. +#if LIBCURL_VERSION_NUM >= 0x075500
  32. +#define PROTOCOLS "HTTP,HTTPS,FTP,FTPS"
  33. +#else
  34. #define PROTOCOLS (CURLPROTO_HTTP | CURLPROTO_HTTPS | \
  35. CURLPROTO_FTP | CURLPROTO_FTPS)
  36. +#endif
  37. #define CURL_NUM_STATES 8
  38. #define CURL_NUM_ACB 8
  39. @@ -509,9 +516,18 @@ static int curl_init_state(BDRVCURLState *s, CURLState *state)
  40. * obscure protocols. For example, do not allow POP3/SMTP/IMAP see
  41. * CVE-2013-0249.
  42. *
  43. - * Restricting protocols is only supported from 7.19.4 upwards.
  44. + * Restricting protocols is only supported from 7.19.4 upwards. Note:
  45. + * version 7.85.0 deprecates CURLOPT_*PROTOCOLS in favour of a string
  46. + * based CURLOPT_*PROTOCOLS_STR API.
  47. */
  48. -#if LIBCURL_VERSION_NUM >= 0x071304
  49. +#if LIBCURL_VERSION_NUM >= 0x075500
  50. + if (curl_easy_setopt(state->curl,
  51. + CURLOPT_PROTOCOLS_STR, PROTOCOLS) ||
  52. + curl_easy_setopt(state->curl,
  53. + CURLOPT_REDIR_PROTOCOLS_STR, PROTOCOLS)) {
  54. + goto err;
  55. + }
  56. +#elif LIBCURL_VERSION_NUM >= 0x071304
  57. if (curl_easy_setopt(state->curl, CURLOPT_PROTOCOLS, PROTOCOLS) ||
  58. curl_easy_setopt(state->curl, CURLOPT_REDIR_PROTOCOLS, PROTOCOLS)) {
  59. goto err;
  60. @@ -669,7 +685,12 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
  61. const char *file;
  62. const char *cookie;
  63. const char *cookie_secret;
  64. - double d;
  65. + /* CURL >= 7.55.0 uses curl_off_t for content length instead of a double */
  66. +#if LIBCURL_VERSION_NUM >= 0x073700
  67. + curl_off_t cl;
  68. +#else
  69. + double cl;
  70. +#endif
  71. const char *secretid;
  72. const char *protocol_delimiter;
  73. int ret;
  74. @@ -796,27 +817,36 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
  75. }
  76. if (curl_easy_perform(state->curl))
  77. goto out;
  78. - if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
  79. + /* CURL 7.55.0 deprecates CURLINFO_CONTENT_LENGTH_DOWNLOAD in favour of
  80. + * the *_T version which returns a more sensible type for content length.
  81. + */
  82. +#if LIBCURL_VERSION_NUM >= 0x073700
  83. + if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &cl)) {
  84. + goto out;
  85. + }
  86. +#else
  87. + if (curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl)) {
  88. goto out;
  89. }
  90. +#endif
  91. /* Prior CURL 7.19.4 return value of 0 could mean that the file size is not
  92. * know or the size is zero. From 7.19.4 CURL returns -1 if size is not
  93. * known and zero if it is really zero-length file. */
  94. #if LIBCURL_VERSION_NUM >= 0x071304
  95. - if (d < 0) {
  96. + if (cl < 0) {
  97. pstrcpy(state->errmsg, CURL_ERROR_SIZE,
  98. "Server didn't report file size.");
  99. goto out;
  100. }
  101. #else
  102. - if (d <= 0) {
  103. + if (cl <= 0) {
  104. pstrcpy(state->errmsg, CURL_ERROR_SIZE,
  105. "Unknown file size or zero-length file.");
  106. goto out;
  107. }
  108. #endif
  109. - s->len = d;
  110. + s->len = cl;
  111. if ((!strncasecmp(s->url, "http://", strlen("http://"))
  112. || !strncasecmp(s->url, "https://", strlen("https://")))
  113. --
  114. 2.25.1