Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
glog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
glog
Commits
9f8a9a9a
Commit
9f8a9a9a
authored
Oct 31, 2017
by
Fumitoshi Ukai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shell escape arguments to /bin/mail.
parent
56b81ea7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletion
+40
-1
logging.cc
src/logging.cc
+40
-1
No files found.
src/logging.cc
View file @
9f8a9a9a
...
...
@@ -1730,6 +1730,42 @@ void SetExitOnDFatal(bool value) {
}
// namespace internal
}
// namespace base
// Shell-escaping as we need to shell out ot /bin/mail.
static
const
char
kDontNeedShellEscapeChars
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+-_.=/:,@"
;
static
string
ShellEscape
(
const
string
&
src
)
{
string
result
;
if
(
!
src
.
empty
()
&&
// empty string needs quotes
src
.
find_first_not_of
(
kDontNeedShellEscapeChars
)
==
string
::
npos
)
{
// only contains chars that don't need quotes; it's fine
result
.
assign
(
src
);
}
else
if
(
src
.
find_first_of
(
'\''
)
==
string
::
npos
)
{
// no single quotes; just wrap it in single quotes
result
.
assign
(
"'"
);
result
.
append
(
src
);
result
.
append
(
"'"
);
}
else
{
// needs double quote escaping
result
.
assign
(
"
\"
"
);
for
(
size_t
i
=
0
;
i
<
src
.
size
();
++
i
)
{
switch
(
src
[
i
])
{
case
'\\'
:
case
'$'
:
case
'"'
:
case
'`'
:
result
.
append
(
"
\\
"
);
}
result
.
append
(
src
,
i
,
1
);
}
result
.
append
(
"
\"
"
);
}
return
result
;
}
// use_logging controls whether the logging functions LOG/VLOG are used
// to log errors. It should be set to false when the caller holds the
// log_mutex.
...
...
@@ -1745,7 +1781,10 @@ static bool SendEmailInternal(const char*dest, const char *subject,
}
string
cmd
=
FLAGS_logmailer
+
" -s
\"
"
+
subject
+
"
\"
"
+
dest
;
FLAGS_logmailer
+
" -s"
+
ShellEscape
(
subject
)
+
" "
+
ShellEscape
(
dest
);
VLOG
(
4
)
<<
"Mailing command: "
<<
cmd
;
FILE
*
pipe
=
popen
(
cmd
.
c_str
(),
"w"
);
if
(
pipe
!=
NULL
)
{
// Add the body if we have one
...
...
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