[PATCH] esx: Satisfy curl type checks

Michal Privoznik via Devel posted 1 patch 1 day, 9 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/45ba8e298f87439253a61e9982074a956aeafd3d.1757330527.git.mprivozn@redhat.com
src/esx/esx_stream.c |  2 +-
src/esx/esx_util.c   |  4 ++--
src/esx/esx_util.h   |  4 ++--
src/esx/esx_vi.c     | 18 +++++++++---------
4 files changed, 14 insertions(+), 14 deletions(-)
[PATCH] esx: Satisfy curl type checks
Posted by Michal Privoznik via Devel 1 day, 9 hours ago
From: Michal Privoznik <mprivozn@redhat.com>

Since its commit [1] curl now performs type checks on
curl_easy_setopt(). Some options expect long but we're passing an
int. The fix consists mostly of specifying type of numbers passed
to the function. Except for two cases: proxy_type and proxy_port
which are stored in a structure of ours (_esxUtil_ParsedUri).
These have their types switched from int to long and unsigned
long, respectively.

1: https://github.com/curl/curl/commit/79b4e56b3f30dc1ac28a81128a07d27338e5219e
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/esx/esx_stream.c |  2 +-
 src/esx/esx_util.c   |  4 ++--
 src/esx/esx_util.h   |  4 ++--
 src/esx/esx_vi.c     | 18 +++++++++---------
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/esx/esx_stream.c b/src/esx/esx_stream.c
index 1439940330..4f3ca09379 100644
--- a/src/esx/esx_stream.c
+++ b/src/esx/esx_stream.c
@@ -411,7 +411,7 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_READDATA, streamPriv);
     } else {
         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_UPLOAD, 0);
-        curl_easy_setopt(streamPriv->curl->handle, CURLOPT_HTTPGET, 1);
+        curl_easy_setopt(streamPriv->curl->handle, CURLOPT_HTTPGET, 1L);
         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_WRITEFUNCTION,
                          esxVI_CURL_WriteStream);
         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_WRITEDATA, streamPriv);
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 7ee0e5f7c0..8e725ed04f 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -125,8 +125,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI *uri)
 
                 *tmp++ = '\0';
 
-                if (virStrToLong_i(tmp, NULL, 10,
-                                   &(*parsedUri)->proxy_port) < 0 ||
+                if (virStrToLong_ul(tmp, NULL, 10,
+                                    &(*parsedUri)->proxy_port) < 0 ||
                     (*parsedUri)->proxy_port < 1 ||
                     (*parsedUri)->proxy_port > 65535) {
                     virReportError(VIR_ERR_INVALID_ARG,
diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h
index 58bc44e744..51f1151eb7 100644
--- a/src/esx/esx_util.h
+++ b/src/esx/esx_util.h
@@ -40,9 +40,9 @@ struct _esxUtil_ParsedUri {
     bool noVerify;
     bool autoAnswer;
     bool proxy;
-    int proxy_type;
+    long proxy_type;
     char *proxy_hostname;
-    int proxy_port;
+    unsigned long proxy_port;
     char *path;
     char *cacert;
 };
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index d25f819bc5..65e19e179e 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -315,13 +315,13 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri)
     }
 
     curl_easy_setopt(curl->handle, CURLOPT_USERAGENT, "libvirt-esx");
-    curl_easy_setopt(curl->handle, CURLOPT_NOSIGNAL, 1);
-    curl_easy_setopt(curl->handle, CURLOPT_HEADER, 0);
-    curl_easy_setopt(curl->handle, CURLOPT_FOLLOWLOCATION, 0);
+    curl_easy_setopt(curl->handle, CURLOPT_NOSIGNAL, 1L);
+    curl_easy_setopt(curl->handle, CURLOPT_HEADER, 0L);
+    curl_easy_setopt(curl->handle, CURLOPT_FOLLOWLOCATION, 0L);
     curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYPEER,
-                     parsedUri->noVerify ? 0 : 1);
+                     parsedUri->noVerify ? 0L : 1L);
     curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYHOST,
-                     parsedUri->noVerify ? 0 : 2);
+                     parsedUri->noVerify ? 0L : 2L);
     curl_easy_setopt(curl->handle, CURLOPT_COOKIEFILE, "");
     curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->headers);
     curl_easy_setopt(curl->handle, CURLOPT_READFUNCTION,
@@ -386,8 +386,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
         curl_easy_setopt(curl->handle, CURLOPT_URL, url);
         curl_easy_setopt(curl->handle, CURLOPT_RANGE, range);
         curl_easy_setopt(curl->handle, CURLOPT_WRITEDATA, &buffer);
-        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0);
-        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1);
+        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0L);
+        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
 
         responseCode = esxVI_CURL_Perform(curl, url);
     }
@@ -426,7 +426,7 @@ esxVI_CURL_Upload(esxVI_CURL *curl, const char *url, const char *content)
         curl_easy_setopt(curl->handle, CURLOPT_URL, url);
         curl_easy_setopt(curl->handle, CURLOPT_RANGE, NULL);
         curl_easy_setopt(curl->handle, CURLOPT_READDATA, &content);
-        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1);
+        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
         curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, strlen(content));
 
         responseCode = esxVI_CURL_Perform(curl, url);
@@ -1223,7 +1223,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
         curl_easy_setopt(ctx->curl->handle, CURLOPT_URL, ctx->url);
         curl_easy_setopt(ctx->curl->handle, CURLOPT_RANGE, NULL);
         curl_easy_setopt(ctx->curl->handle, CURLOPT_WRITEDATA, &buffer);
-        curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0);
+        curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0L);
         curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDS, request);
         curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDSIZE, strlen(request));
 
-- 
2.49.1
Re: [PATCH] esx: Satisfy curl type checks
Posted by Ján Tomko via Devel 1 day, 9 hours ago
On a Monday in 2025, Michal Privoznik via Devel wrote:
>From: Michal Privoznik <mprivozn@redhat.com>
>
>Since its commit [1] curl now performs type checks on
>curl_easy_setopt(). Some options expect long but we're passing an
>int. The fix consists mostly of specifying type of numbers passed
>to the function. Except for two cases: proxy_type and proxy_port
>which are stored in a structure of ours (_esxUtil_ParsedUri).
>These have their types switched from int to long and unsigned
>long, respectively.
>
>1: https://github.com/curl/curl/commit/79b4e56b3f30dc1ac28a81128a07d27338e5219e
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/esx/esx_stream.c |  2 +-
> src/esx/esx_util.c   |  4 ++--
> src/esx/esx_util.h   |  4 ++--
> src/esx/esx_vi.c     | 18 +++++++++---------
> 4 files changed, 14 insertions(+), 14 deletions(-)
>

I've already sent a similar patch last Tuesday
https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/5BHY77MAQQORU3SDKVDABEYIZKVSKPRJ/
It changes more occurences of int constants, but does not switch the
proxy* types

Jano

>diff --git a/src/esx/esx_stream.c b/src/esx/esx_stream.c
>index 1439940330..4f3ca09379 100644
>--- a/src/esx/esx_stream.c
>+++ b/src/esx/esx_stream.c
>@@ -411,7 +411,7 @@ esxStreamOpen(virStreamPtr stream, esxPrivate *priv, const char *url,
>         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_READDATA, streamPriv);
>     } else {
>         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_UPLOAD, 0);
>-        curl_easy_setopt(streamPriv->curl->handle, CURLOPT_HTTPGET, 1);
>+        curl_easy_setopt(streamPriv->curl->handle, CURLOPT_HTTPGET, 1L);
>         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_WRITEFUNCTION,
>                          esxVI_CURL_WriteStream);
>         curl_easy_setopt(streamPriv->curl->handle, CURLOPT_WRITEDATA, streamPriv);
>diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
>index 7ee0e5f7c0..8e725ed04f 100644
>--- a/src/esx/esx_util.c
>+++ b/src/esx/esx_util.c
>@@ -125,8 +125,8 @@ esxUtil_ParseUri(esxUtil_ParsedUri **parsedUri, virURI *uri)
>
>                 *tmp++ = '\0';
>
>-                if (virStrToLong_i(tmp, NULL, 10,
>-                                   &(*parsedUri)->proxy_port) < 0 ||
>+                if (virStrToLong_ul(tmp, NULL, 10,
>+                                    &(*parsedUri)->proxy_port) < 0 ||
>                     (*parsedUri)->proxy_port < 1 ||
>                     (*parsedUri)->proxy_port > 65535) {
>                     virReportError(VIR_ERR_INVALID_ARG,
>diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h
>index 58bc44e744..51f1151eb7 100644
>--- a/src/esx/esx_util.h
>+++ b/src/esx/esx_util.h
>@@ -40,9 +40,9 @@ struct _esxUtil_ParsedUri {
>     bool noVerify;
>     bool autoAnswer;
>     bool proxy;
>-    int proxy_type;
>+    long proxy_type;
>     char *proxy_hostname;
>-    int proxy_port;
>+    unsigned long proxy_port;
>     char *path;
>     char *cacert;
> };
>diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
>index d25f819bc5..65e19e179e 100644
>--- a/src/esx/esx_vi.c
>+++ b/src/esx/esx_vi.c
>@@ -315,13 +315,13 @@ esxVI_CURL_Connect(esxVI_CURL *curl, esxUtil_ParsedUri *parsedUri)
>     }
>
>     curl_easy_setopt(curl->handle, CURLOPT_USERAGENT, "libvirt-esx");
>-    curl_easy_setopt(curl->handle, CURLOPT_NOSIGNAL, 1);
>-    curl_easy_setopt(curl->handle, CURLOPT_HEADER, 0);
>-    curl_easy_setopt(curl->handle, CURLOPT_FOLLOWLOCATION, 0);
>+    curl_easy_setopt(curl->handle, CURLOPT_NOSIGNAL, 1L);
>+    curl_easy_setopt(curl->handle, CURLOPT_HEADER, 0L);
>+    curl_easy_setopt(curl->handle, CURLOPT_FOLLOWLOCATION, 0L);
>     curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYPEER,
>-                     parsedUri->noVerify ? 0 : 1);
>+                     parsedUri->noVerify ? 0L : 1L);
>     curl_easy_setopt(curl->handle, CURLOPT_SSL_VERIFYHOST,
>-                     parsedUri->noVerify ? 0 : 2);
>+                     parsedUri->noVerify ? 0L : 2L);
>     curl_easy_setopt(curl->handle, CURLOPT_COOKIEFILE, "");
>     curl_easy_setopt(curl->handle, CURLOPT_HTTPHEADER, curl->headers);
>     curl_easy_setopt(curl->handle, CURLOPT_READFUNCTION,
>@@ -386,8 +386,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
>         curl_easy_setopt(curl->handle, CURLOPT_URL, url);
>         curl_easy_setopt(curl->handle, CURLOPT_RANGE, range);
>         curl_easy_setopt(curl->handle, CURLOPT_WRITEDATA, &buffer);
>-        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0);
>-        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1);
>+        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 0L);
>+        curl_easy_setopt(curl->handle, CURLOPT_HTTPGET, 1L);
>
>         responseCode = esxVI_CURL_Perform(curl, url);
>     }
>@@ -426,7 +426,7 @@ esxVI_CURL_Upload(esxVI_CURL *curl, const char *url, const char *content)
>         curl_easy_setopt(curl->handle, CURLOPT_URL, url);
>         curl_easy_setopt(curl->handle, CURLOPT_RANGE, NULL);
>         curl_easy_setopt(curl->handle, CURLOPT_READDATA, &content);
>-        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1);
>+        curl_easy_setopt(curl->handle, CURLOPT_UPLOAD, 1L);
>         curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, strlen(content));
>
>         responseCode = esxVI_CURL_Perform(curl, url);
>@@ -1223,7 +1223,7 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
>         curl_easy_setopt(ctx->curl->handle, CURLOPT_URL, ctx->url);
>         curl_easy_setopt(ctx->curl->handle, CURLOPT_RANGE, NULL);
>         curl_easy_setopt(ctx->curl->handle, CURLOPT_WRITEDATA, &buffer);
>-        curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0);
>+        curl_easy_setopt(ctx->curl->handle, CURLOPT_UPLOAD, 0L);
>         curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDS, request);
>         curl_easy_setopt(ctx->curl->handle, CURLOPT_POSTFIELDSIZE, strlen(request));
>
>-- 
>2.49.1
>