[vlc-commits] [Git][videolan/vlc][3.0.x] access: ftp: check command strings for control chars
François Cartegnie (@fcartegnie)
gitlab at videolan.org
Tue Sep 8 09:24:20 UTC 2026
François Cartegnie pushed to branch 3.0.x at VideoLAN / VLC
Commits:
cd492117 by François Cartegnie at 2026-09-08T11:16:50+02:00
access: ftp: check command strings for control chars
fix #30078
Reported-By: Mohammadmobinjavan(Ma3terPwner) and Adel Piri
(cherry picked from commit 19650772d4d73e8713ab6852e65fc7401eb36aac)
- - - - -
1 changed file:
- modules/access/ftp.c
Changes:
=====================================
modules/access/ftp.c
=====================================
@@ -357,6 +357,21 @@ static void clearCmd( access_sys_t *p_sys )
}
}
+/* Sanitize for the protocol rfc1738. epscially \n\r */
+static bool HasControlChar( const char *p )
+{
+ if( p )
+ {
+ for( ; *p; p++ )
+ {
+ unsigned char c = (unsigned char)*p;
+ if( (c < 0x20 && c != '\t') || c == 0x7F || c == 0xFF /* IAC control byte */ )
+ return true;
+ }
+ }
+ return false;
+}
+
static int Login( vlc_object_t *p_access, access_sys_t *p_sys, const char *path )
{
int i_answer;
@@ -459,6 +474,13 @@ static int Login( vlc_object_t *p_access, access_sys_t *p_sys, const char *path
{
const char *psz_username = credential.psz_username;
+ if( HasControlChar( credential.psz_username ) ||
+ HasControlChar( credential.psz_password ) )
+ {
+ msg_Err( p_access, "Invalid chars in the username/password" );
+ break;
+ }
+
if( psz_username == NULL ) /* use anonymous by default */
psz_username = "anonymous";
@@ -522,10 +544,14 @@ static int LoginUserPwd( vlc_object_t *p_access, access_sys_t *p_sys,
char *psz;
msg_Dbg( p_access, "account needed" );
psz = var_InheritString( p_access, "ftp-account" );
- if( ftp_SendCommand( p_access, p_sys, "ACCT %s",
+ bool badchars = HasControlChar( psz );
+ if( badchars ||
+ ftp_SendCommand( p_access, p_sys, "ACCT %s",
psz ) < 0 ||
ftp_RecvCommand( p_access, p_sys, &i_answer, NULL ) < 0 )
{
+ if( badchars )
+ msg_Err( p_access, "Invalid chars in the ftp-account" );
free( psz );
return -1;
}
@@ -637,7 +663,7 @@ error:
}
-static int parseURL( vlc_url_t *url, const char *path, enum tls_mode_e mode )
+static int parseURL( vlc_object_t *p_obj, vlc_url_t *url, const char *path, enum tls_mode_e mode )
{
if( path == NULL )
return VLC_EGENERIC;
@@ -678,6 +704,11 @@ static int parseURL( vlc_url_t *url, const char *path, enum tls_mode_e mode )
return VLC_EGENERIC; /* ASCII and directory not supported */
}
vlc_uri_decode( url->psz_path );
+ if( HasControlChar( url->psz_path ) )
+ {
+ msg_Err( p_obj, "Invalid chars in the path" );
+ return VLC_EGENERIC;
+ }
return VLC_SUCCESS;
}
@@ -704,7 +735,7 @@ static int InOpen( vlc_object_t *p_this )
if( readTLSMode( p_this, p_sys, p_access->psz_name ) )
goto exit_error;
- if( parseURL( &p_sys->url, p_access->psz_url, p_sys->tlsmode ) )
+ if( parseURL( p_this,&p_sys->url, p_access->psz_url, p_sys->tlsmode ) )
goto exit_error;
if( Connect( p_this, p_sys, p_access->psz_url ) )
@@ -790,7 +821,7 @@ static int OutOpen( vlc_object_t *p_this )
if( readTLSMode( p_this, p_sys, p_access->psz_access ) )
goto exit_error;
- if( parseURL( &p_sys->url, p_access->psz_path, p_sys->tlsmode ) )
+ if( parseURL( p_this, &p_sys->url, p_access->psz_path, p_sys->tlsmode ) )
goto exit_error;
if( p_sys->url.psz_path == NULL )
{
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/cd49211700bc7ce7e68f546a5db9c8f0d44b167a
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/cd49211700bc7ce7e68f546a5db9c8f0d44b167a
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