Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
11cd9e3c
Commit
11cd9e3c
authored
Oct 04, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove more evil characters with filename_sanitize() (fix #5309)
parent
5b24e072
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
39 deletions
+37
-39
src/text/strings.c
src/text/strings.c
+37
-39
No files found.
src/text/strings.c
View file @
11cd9e3c
...
@@ -968,62 +968,60 @@ char *str_format( vlc_object_t *p_this, const char *psz_src )
...
@@ -968,62 +968,60 @@ char *str_format( vlc_object_t *p_this, const char *psz_src )
}
}
/**
/**
* Remove forbidden characters from filenames (including slashes)
* Remove forbidden, potentially forbidden and otherwise evil characters from
* filenames. This includes slashes, and popular characters like colon
* (on Unix anyway), so this should only be used for automatically generated
* filenames.
* \warning Do not use this on full paths,
* only single file names without any directory separator!
*/
*/
void
filename_sanitize
(
char
*
str
)
void
filename_sanitize
(
char
*
str
)
{
{
#if defined( WIN32 ) || defined( __OS2__ )
unsigned
char
c
;
char
*
str_base
=
str
;
#endif
if
(
*
str
==
'.'
&&
(
str
[
1
]
==
'\0'
||
(
str
[
1
]
==
'.'
&&
str
[
2
]
==
'\0'
)
)
)
/* Special file names, not allowed */
if
(
!
strcmp
(
str
,
"."
)
||
!
strcmp
(
str
,
".."
)
)
{
{
while
(
*
str
)
while
(
*
str
)
{
*
(
str
++
)
=
'_'
;
*
str
=
'_'
;
str
++
;
}
return
;
return
;
}
}
#if defined( WIN32 ) || defined( __OS2__ )
/* On platforms not using UTF-7, VLC cannot access non-Unicode paths.
// Change leading spaces into underscores
* Also, some file systems require Unicode file names.
while
(
*
str
&&
*
str
==
' '
)
* NOTE: This may inserts '?' thus is done replacing '?' with '_'. */
*
str
++
=
'_'
;
EnsureUTF8
(
str
);
#endif
while
(
*
str
)
/* Avoid leading spaces to please Windows. */
while
(
(
c
=
*
str
)
!=
'\0'
)
{
{
switch
(
*
str
)
if
(
c
!=
' '
)
break
;
*
(
str
++
)
=
'_'
;
}
char
*
start
=
str
;
while
(
(
c
=
*
str
)
!=
'\0'
)
{
{
case
'/'
:
/* Non-printable characters are not a good idea */
#if defined( __APPLE__ )
if
(
c
<
32
)
case
':'
:
*
str
=
'_'
;
#elif defined( WIN32 ) || defined( __OS2__ )
/* This is the list of characters not allowed by Microsoft.
case
'\\'
:
* We also black-list them on Unix as they may be confusing, and are
case
'*'
:
* not supported by some file system types (notably CIFS). */
case
'"'
:
else
if
(
strchr
(
"/:
\\
*
\"
?|<>"
,
c
)
!=
NULL
)
case
'?'
:
case
':'
:
case
'|'
:
case
'<'
:
case
'>'
:
#endif
*
str
=
'_'
;
*
str
=
'_'
;
}
str
++
;
str
++
;
}
}
#if defined( WIN32 ) || defined( __OS2__ )
/* Avoid trailing spaces also to please Windows. */
// Change trailing spaces into underscores
while
(
str
>
start
)
str
--
;
while
(
str
!=
str_base
)
{
{
if
(
*
str
!=
' '
)
if
(
*
(
--
str
)
!=
' '
)
break
;
break
;
*
str
--
=
'_'
;
*
str
=
'_'
;
}
}
#endif
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment