Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Libraries
pistache
Commits
4a9ffad3
Commit
4a9ffad3
authored
May 31, 2018
by
Jeff VanDyke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close 2 file descriptors opened from serveFile - avoid crash
parent
fcb83f89
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
3 deletions
+11
-3
include/pistache/stream.h
include/pistache/stream.h
+2
-1
src/common/http.cc
src/common/http.cc
+1
-0
src/common/stream.cc
src/common/stream.cc
+8
-2
No files found.
include/pistache/stream.h
View file @
4a9ffad3
...
@@ -156,10 +156,11 @@ struct Buffer {
...
@@ -156,10 +156,11 @@ struct Buffer {
};
};
struct
FileBuffer
{
struct
FileBuffer
{
FileBuffer
()
{
}
FileBuffer
()
=
delete
;
FileBuffer
(
const
char
*
fileName
);
FileBuffer
(
const
char
*
fileName
);
FileBuffer
(
const
std
::
string
&
fileName
);
FileBuffer
(
const
std
::
string
&
fileName
);
~
FileBuffer
();
std
::
string
fileName
()
const
{
return
fileName_
;
}
std
::
string
fileName
()
const
{
return
fileName_
;
}
Fd
fd
()
const
{
return
fd_
;
}
Fd
fd
()
const
{
return
fd_
;
}
...
...
src/common/http.cc
View file @
4a9ffad3
...
@@ -675,6 +675,7 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
...
@@ -675,6 +675,7 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
}
}
int
res
=
::
fstat
(
fd
,
&
sb
);
int
res
=
::
fstat
(
fd
,
&
sb
);
close
(
fd
);
// Done with fd, close before error can be thrown
if
(
res
==
-
1
)
{
if
(
res
==
-
1
)
{
throw
HttpError
(
Code
::
Internal_Server_Error
,
""
);
throw
HttpError
(
Code
::
Internal_Server_Error
,
""
);
}
}
...
...
src/common/stream.cc
View file @
4a9ffad3
...
@@ -16,17 +16,23 @@
...
@@ -16,17 +16,23 @@
namespace
Pistache
{
namespace
Pistache
{
FileBuffer
::
FileBuffer
(
const
char
*
fileName
)
FileBuffer
::
FileBuffer
(
const
char
*
fileName
)
:
fileName_
(
fileName
)
:
fileName_
(
fileName
)
,
fd_
(
-
1
)
{
{
init
(
fileName
);
init
(
fileName
);
}
}
FileBuffer
::
FileBuffer
(
const
std
::
string
&
fileName
)
FileBuffer
::
FileBuffer
(
const
std
::
string
&
fileName
)
:
fileName_
(
fileName
)
:
fileName_
(
fileName
)
,
fd_
(
-
1
)
{
{
init
(
fileName
.
c_str
());
init
(
fileName
.
c_str
());
}
}
FileBuffer
::~
FileBuffer
()
{
if
(
fd_
>
-
1
)
close
(
fd_
);
}
void
void
FileBuffer
::
init
(
const
char
*
fileName
)
FileBuffer
::
init
(
const
char
*
fileName
)
{
{
...
...
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