Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
b0c4fd6d
Commit
b0c4fd6d
authored
10 years ago
by
kwolekr
Browse files
Options
Downloads
Patches
Plain Diff
Settings: Sanitize value for multiline terminator tokens
parent
f114fc74
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/settings.cpp
+28
-6
28 additions, 6 deletions
src/settings.cpp
src/settings.h
+2
-0
2 additions, 0 deletions
src/settings.h
with
30 additions
and
6 deletions
src/settings.cpp
+
28
−
6
View file @
b0c4fd6d
...
...
@@ -63,6 +63,32 @@ Settings & Settings::operator = (const Settings &other)
}
std
::
string
Settings
::
sanitizeName
(
const
std
::
string
&
name
)
{
std
::
string
n
(
name
);
for
(
const
char
*
s
=
"
\t\n\v\f\r\b
=
\"
{}#"
;
*
s
;
s
++
)
n
.
erase
(
std
::
remove
(
n
.
begin
(),
n
.
end
(),
*
s
),
n
.
end
());
return
n
;
}
std
::
string
Settings
::
sanitizeValue
(
const
std
::
string
&
value
)
{
std
::
string
v
(
value
);
size_t
p
=
0
;
if
(
v
.
substr
(
0
,
3
)
==
"
\"\"\"
"
)
v
.
erase
(
0
,
3
);
while
((
p
=
v
.
find
(
"
\n\"\"\"
"
))
!=
std
::
string
::
npos
)
v
.
erase
(
p
,
4
);
return
v
;
}
std
::
string
Settings
::
getMultiline
(
std
::
istream
&
is
,
size_t
*
num_lines
)
{
size_t
lines
=
1
;
...
...
@@ -683,11 +709,7 @@ void Settings::setEntry(const std::string &name, const void *data,
{
Settings
*
old_group
=
NULL
;
// Strip any potentially dangerous characters from the name (note the value
// has no such restrictions)
std
::
string
n
(
name
);
for
(
const
char
*
s
=
"
\t\n\v\f\r\b
=
\"
"
;
*
s
;
s
++
)
n
.
erase
(
std
::
remove
(
n
.
begin
(),
n
.
end
(),
*
s
),
n
.
end
());
std
::
string
n
=
sanitizeName
(
name
);
{
JMutexAutoLock
lock
(
m_mutex
);
...
...
@@ -695,7 +717,7 @@ void Settings::setEntry(const std::string &name, const void *data,
SettingsEntry
&
entry
=
set_default
?
m_defaults
[
n
]
:
m_settings
[
n
];
old_group
=
entry
.
group
;
entry
.
value
=
set_group
?
""
:
*
(
const
std
::
string
*
)
data
;
entry
.
value
=
set_group
?
""
:
sanitizeValue
(
*
(
const
std
::
string
*
)
data
)
;
entry
.
group
=
set_group
?
*
(
Settings
**
)
data
:
NULL
;
entry
.
is_group
=
set_group
;
}
...
...
This diff is collapsed.
Click to expand it.
src/settings.h
+
2
−
0
View file @
b0c4fd6d
...
...
@@ -112,6 +112,8 @@ class Settings {
bool
updateConfigObject
(
std
::
istream
&
is
,
std
::
ostream
&
os
,
const
std
::
string
&
end
,
u32
tab_depth
=
0
);
static
std
::
string
sanitizeName
(
const
std
::
string
&
name
);
static
std
::
string
sanitizeValue
(
const
std
::
string
&
value
);
static
std
::
string
getMultiline
(
std
::
istream
&
is
,
size_t
*
num_lines
=
NULL
);
static
void
printEntry
(
std
::
ostream
&
os
,
const
std
::
string
&
name
,
const
SettingsEntry
&
entry
,
u32
tab_depth
=
0
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment