[vlc-commits] [Git][videolan/vlc][master] 2 commits: ftp: simplify PASV parsing

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Nov 12 09:41:59 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f24a25c0 by Rémi Denis-Courmont at 2026-11-12T09:23:52+00:00
ftp: simplify PASV parsing

- - - - -
38b0dd11 by Rémi Denis-Courmont at 2026-11-12T09:23:52+00:00
ftp: only allow PASV to same IPv4 address

- - - - -


1 changed file:

- modules/access/ftp.c


Changes:

=====================================
modules/access/ftp.c
=====================================
@@ -1400,7 +1400,7 @@ static int Control( stream_t *p_access, int i_query, va_list args )
 static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
                             uint64_t i_start, bool b_directory )
 {
-    char psz_ipv4[16], *psz_ip = p_sys->sz_epsv_ip;
+    char ipv4buf[16], *psz_ip = p_sys->sz_epsv_ip;
     int  i_answer;
     char *psz_arg, *psz_parser;
     int  i_port;
@@ -1433,19 +1433,29 @@ static int ftp_StartStream( vlc_object_t *p_access, access_sys_t *p_sys,
     }
     else
     {
-        unsigned a1, a2, a3, a4, p1, p2;
-
-        if( ( sscanf( psz_parser, "(%u,%u,%u,%u,%u,%u", &a1, &a2, &a3, &a4,
-                      &p1, &p2 ) < 6 ) || ( a1 > 255 ) || ( a2 > 255 )
-         || ( a3 > 255 ) || ( a4 > 255 ) || ( p1 > 255 ) || ( p2 > 255 ) )
+        unsigned char a1, a2, a3, a4, p1, p2;
+        int fd = vlc_tls_GetFD( p_sys->cmd );
+        union {
+            struct sockaddr    sa;
+            struct sockaddr_in sin;
+        } su;
+        socklen_t salen = sizeof (su);
+
+        if( sscanf( psz_parser, "(%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
+                    &a1, &a2, &a3, &a4, &p1, &p2 ) < 6 ||
+            getsockname( fd, &su.sa, &salen ) < 0 ||
+            salen < sizeof (struct sockaddr_in) ||
+            su.sin.sin_family != AF_INET ||
+            su.sin.sin_addr.s_addr != htonl((a1<<24)|(a2<<16)|(a3<<8)|a4))
         {
             free( psz_arg );
             msg_Err( p_access, "cannot parse passive mode response" );
             return VLC_EGENERIC;
         }
 
-        snprintf( psz_ipv4, ARRAY_SIZE(psz_ipv4), "%u.%u.%u.%u", a1, a2, a3, a4 );
-        psz_ip = psz_ipv4;
+        snprintf( ipv4buf, sizeof (ipv4buf), "%hhu.%hhu.%hhu.%hhu",
+                  a1, a2, a3, a4 );
+        psz_ip = ipv4buf;
         i_port = (p1 << 8) | p2;
     }
     free( psz_arg );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6b5f85b1d1bb7f4fc0545078338dc040cc3f3d7e...38b0dd11171b09b1837b859356f76e13cb648989

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6b5f85b1d1bb7f4fc0545078338dc040cc3f3d7e...38b0dd11171b09b1837b859356f76e13cb648989
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list