Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
20eb7ae5
Commit
20eb7ae5
authored
13 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
bug 1362: check return codes of fgets/mktemps, and prevent memory corruption due to strcpy
parent
44ee4548
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LCS/Common/src/SystemUtil.cc
+19
-5
19 additions, 5 deletions
LCS/Common/src/SystemUtil.cc
with
19 additions
and
5 deletions
LCS/Common/src/SystemUtil.cc
+
19
−
5
View file @
20eb7ae5
...
...
@@ -28,6 +28,7 @@
#include
<cstdlib>
#include
<cstdio>
#include
<cstring>
#include
<cerrno>
#include
<climits>
#if defined(__APPLE__)
...
...
@@ -92,7 +93,8 @@ int remoteCopy (const string& localFile,
else
{
// construct the error message
while
(
!
feof
(
f
))
{
fgets
(
outputLine
,
200
,
f
);
if
(
!
fgets
(
outputLine
,
200
,
f
))
break
;
if
(
!
feof
(
f
))
{
outputString
+=
string
(
outputLine
);
}
...
...
@@ -144,7 +146,8 @@ int copyFromRemote(const string& remoteHost,
else
{
// construct the error message
while
(
!
feof
(
f
))
{
fgets
(
outputLine
,
200
,
f
);
if
(
!
fgets
(
outputLine
,
200
,
f
))
break
;
if
(
!
feof
(
f
))
{
outputString
+=
string
(
outputLine
);
}
...
...
@@ -170,13 +173,24 @@ string getTempFileName(const string& format)
char
tempFileName
[
256
];
if
(
format
.
find
(
"XXXXXX"
,
0
)
!=
string
::
npos
)
{
// did user specify mask?
strcpy
(
tempFileName
,
format
.
c_str
());
// use user-mask
str
n
cpy
(
tempFileName
,
format
.
c_str
()
,
sizeof
tempFileName
);
// use user-mask
}
else
{
strcpy
(
tempFileName
,
"/tmp/LOFAR_XXXXXX"
);
// use default mask
str
n
cpy
(
tempFileName
,
"/tmp/LOFAR_XXXXXX"
,
sizeof
tempFileName
);
// use default mask
}
mkstemp
(
tempFileName
);
// let OS invent the name
// note that if we actually cut off the mask, it will likely be invalid because
// it has to end in XXXXXX
tempFileName
[
sizeof
tempFileName
-
1
]
=
0
;
if
(
!
mkstemp
(
tempFileName
))
{
// let OS invent the name
if
(
errno
==
EINVAL
)
LOG_ERROR
(
formatString
(
"Invalid temporary file-name mask %s (specified %s)"
,
tempFileName
,
format
.
c_str
()));
else
LOG_ERROR
(
formatString
(
"Could not create temporary file with mask %s (specified %s)"
,
tempFileName
,
format
.
c_str
()));
return
""
;
}
return
string
(
tempFileName
);
}
...
...
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