[vlc-commits] [Git][videolan/vlc][master] 5 commits: smb2: vlc_smb2_resolve: return an error code

Thomas Guillem (@tguillem) gitlab at videolan.org
Tue Jun 7 12:59:42 UTC 2022



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
cbf16982 by Thomas Guillem at 2022-06-07T12:47:13+00:00
smb2: vlc_smb2_resolve: return an error code

- - - - -
99a4deaf by Thomas Guillem at 2022-06-07T12:47:13+00:00
smb2: forward the vlc_interrupt_unregister() return value

- - - - -
bb33734c by Thomas Guillem at 2022-06-07T12:47:13+00:00
smb2: vlc_smb2_resolve: return -EINTR when interrupted

- - - - -
fea7a18a by Thomas Guillem at 2022-06-07T12:47:13+00:00
smb2: handle vlc_smb2_resolve interruption

- - - - -
797e1f3b by Thomas Guillem at 2022-06-07T12:47:13+00:00
smb2: explicitly handle -EINTR

Even if it is redundant with vlc_killed() (but not all APIs return
-EINTR when killed).

- - - - -


1 changed file:

- modules/access/smb2.c


Changes:

=====================================
modules/access/smb2.c
=====================================
@@ -65,16 +65,26 @@ netbios_ns_interrupt_register(netbios_ns *ns)
     vlc_interrupt_register(netbios_ns_interrupt_callback, ns);
 }
 
-static inline void
+static inline int
 netbios_ns_interrupt_unregister(void)
 {
-    vlc_interrupt_unregister();
+    return vlc_interrupt_unregister();
 }
 
 #else
 
-#define netbios_ns_interrupt_register( ns ) do {} while (0)
-#define netbios_ns_interrupt_unregister() do {} while (0)
+static inline void
+netbios_ns_interrupt_register(netbios_ns *ns)
+{
+    (void) ns;
+}
+
+static inline int
+netbios_ns_interrupt_unregister(void)
+{
+    return 0;
+}
+
 #endif
 
 #endif
@@ -763,18 +773,19 @@ error:
     return op.error_status;
 }
 
-static char *
-vlc_smb2_resolve(stream_t *access, const char *host, unsigned port)
+static int
+vlc_smb2_resolve(stream_t *access, const char *host, unsigned port,
+                 char **out_host)
 {
     (void) access;
     if (!host)
-        return NULL;
+        return -ENOENT;
 
 #ifdef HAVE_DSM
     /* Test if the host is an IP */
     struct in_addr addr;
     if (inet_pton(AF_INET, host, &addr) == 1)
-        return NULL;
+        return -ENOENT;
 
     /* Test if the host can be resolved */
     struct addrinfo *info = NULL;
@@ -782,28 +793,38 @@ vlc_smb2_resolve(stream_t *access, const char *host, unsigned port)
     {
         freeaddrinfo(info);
         /* Let smb2 resolve it */
-        return NULL;
+        return -ENOENT;
     }
 
     /* Test if the host is a netbios name */
-    char *out_host = NULL;
     netbios_ns *ns = netbios_ns_new();
     if (!ns)
-        return NULL;
+        return -ENOMEM;
+
+    int ret = -ENOENT;
     netbios_ns_interrupt_register(ns);
     uint32_t ip4_addr;
     if (netbios_ns_resolve(ns, host, NETBIOS_FILESERVER, &ip4_addr) == 0)
     {
         char ip[INET_ADDRSTRLEN];
         if (inet_ntop(AF_INET, &ip4_addr, ip, sizeof(ip)))
-            out_host = strdup(ip);
+        {
+            *out_host = strdup(ip);
+            ret = 0;
+        }
+    }
+    if (netbios_ns_interrupt_unregister() == EINTR)
+    {
+        if (unlikely(ret == 0))
+            free(*out_host);
+        netbios_ns_destroy(ns);
+        return -EINTR;
     }
-    netbios_ns_interrupt_unregister();
     netbios_ns_destroy(ns);
-    return out_host;
+    return ret;
 #else
     (void) port;
-    return NULL;
+    return -ENOENT;
 #endif
 }
 
@@ -826,13 +847,16 @@ 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);
+    char *resolved_host = NULL;
+    ret = vlc_smb2_resolve(access, sys->encoded_url.psz_host,
+                           sys->encoded_url.i_port, &resolved_host);
 
     /* 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)
+    if (ret == -EINTR)
+        goto error;
+    else if (ret == 0)
     {
         vlc_url_t resolved_url = sys->encoded_url;
         resolved_url.psz_host = resolved_host;
@@ -928,7 +952,7 @@ error:
      * case of network error (EIO) or when the user asked to cancel it
      * (vlc_killed()). Indeed, in these cases, it is useless to try next smb
      * modules. */
-    return vlc_killed() || ret == -EIO ? VLC_ETIMEOUT : VLC_EGENERIC;
+    return ret == -EINTR || ret == -EIO || vlc_killed() ? VLC_ETIMEOUT : VLC_EGENERIC;
 }
 
 static void



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/24aa25bdeec2c2f600d418450550456b295bcb4f...797e1f3b979fca463030608db1513a81228c624c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/24aa25bdeec2c2f600d418450550456b295bcb4f...797e1f3b979fca463030608db1513a81228c624c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list