[vlc-devel] [PATCH 2/2] smb2: resolve is now mandatory

Thomas Guillem thomas at gllm.fr
Fri Nov 6 20:35:48 CET 2020


Either the host is resolved via getaddrinfo() or via netbios. It's
useless to try to connect to smb2 if vlc_smb2_resolve() fails since
libsmb2 will also use getaddrinfo().
---
 modules/access/smb2.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/modules/access/smb2.c b/modules/access/smb2.c
index 53f960efeac..2a267ef78ed 100644
--- a/modules/access/smb2.c
+++ b/modules/access/smb2.c
@@ -693,29 +693,23 @@ Open(vlc_object_t *p_obj)
     if (sys->encoded_url.psz_path == NULL)
         sys->encoded_url.psz_path = (char *) "/";
 
-    char *resolved_host = vlc_smb2_resolve(access, sys->encoded_url.psz_host,
-                                           sys->encoded_url.i_port);
-    const char *host;
+    char *host = vlc_smb2_resolve(access, sys->encoded_url.psz_host,
+                                  sys->encoded_url.i_port);
 
     /* smb2_* functions need a decoded url. Re compose the url from the
      * modified sys->encoded_url (with the resolved host). */
     char *url;
-    if (resolved_host != NULL)
-    {
-        vlc_url_t resolved_url = sys->encoded_url;
-        resolved_url.psz_host = resolved_host;
-        url = vlc_uri_compose(&resolved_url);
-        host = resolved_host;
-    }
-    else
-    {
-        url = vlc_uri_compose(&sys->encoded_url);
-        host = sys->encoded_url.psz_host;
-    }
+    if (host == NULL)
+        goto error;
+
+    vlc_url_t resolved_url = sys->encoded_url;
+    resolved_url.psz_host = host;
+    url = vlc_uri_compose(&resolved_url);
+
     if (!vlc_uri_decode(url))
     {
         free(url);
-        free(resolved_host);
+        free(host);
         goto error;
     }
 
@@ -740,7 +734,7 @@ Open(vlc_object_t *p_obj)
         sys->error_status = 0;
         ret = vlc_smb2_open_share(access, url, &credential);
     }
-    free(resolved_host);
+    free(host);
     free(url);
     if (ret == 0)
         vlc_credential_store(&credential, access);
-- 
2.28.0



More information about the vlc-devel mailing list