Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
e7c34c26
Commit
e7c34c26
authored
Jul 01, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mg_read() with no Content-Length would read until socket is closed
parent
a856971b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
mongoose.c
mongoose.c
+13
-1
unit_test.c
test/unit_test.c
+12
-2
No files found.
mongoose.c
View file @
e7c34c26
...
@@ -1544,6 +1544,12 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) {
...
@@ -1544,6 +1544,12 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) {
int
n
,
buffered_len
,
nread
;
int
n
,
buffered_len
,
nread
;
const
char
*
body
;
const
char
*
body
;
// If Content-Length is not set, read until socket is closed
if
(
conn
->
consumed_content
==
0
&&
conn
->
content_len
==
0
)
{
conn
->
content_len
=
INT64_MAX
;
conn
->
must_close
=
1
;
}
nread
=
0
;
nread
=
0
;
if
(
conn
->
consumed_content
<
conn
->
content_len
)
{
if
(
conn
->
consumed_content
<
conn
->
content_len
)
{
// Adjust number of bytes to read.
// Adjust number of bytes to read.
...
@@ -4889,6 +4895,10 @@ static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
...
@@ -4889,6 +4895,10 @@ static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
!
mg_strcasecmp
(
conn
->
request_info
.
request_method
,
"PUT"
))
{
!
mg_strcasecmp
(
conn
->
request_info
.
request_method
,
"PUT"
))
{
conn
->
content_len
=
-
1
;
conn
->
content_len
=
-
1
;
}
else
{
}
else
{
// Content-Length is not set. Set content_len to maximum possible
// value, instructing mg_read() to read data until socket is closed.
// Message boundary is not known in this case, therefore this
// connection must be closed after
conn
->
content_len
=
0
;
conn
->
content_len
=
0
;
}
}
conn
->
birth_time
=
time
(
NULL
);
conn
->
birth_time
=
time
(
NULL
);
...
@@ -4951,7 +4961,9 @@ static void process_new_connection(struct mg_connection *conn) {
...
@@ -4951,7 +4961,9 @@ static void process_new_connection(struct mg_connection *conn) {
}
}
if
(
ri
->
remote_user
!=
NULL
)
{
if
(
ri
->
remote_user
!=
NULL
)
{
free
((
void
*
)
ri
->
remote_user
);
free
((
void
*
)
ri
->
remote_user
);
ri
->
remote_user
=
NULL
;
// when having connections with and without auth would cause double free and then crash
// Important! When having connections with and without auth
// would cause double free and then crash
ri
->
remote_user
=
NULL
;
}
}
// NOTE(lsm): order is important here. should_keep_alive() call
// NOTE(lsm): order is important here. should_keep_alive() call
...
...
test/unit_test.c
View file @
e7c34c26
...
@@ -220,9 +220,9 @@ static int begin_request_handler_cb(struct mg_connection *conn) {
...
@@ -220,9 +220,9 @@ static int begin_request_handler_cb(struct mg_connection *conn) {
if
(
!
strcmp
(
ri
->
uri
,
"/data"
))
{
if
(
!
strcmp
(
ri
->
uri
,
"/data"
))
{
mg_printf
(
conn
,
"HTTP/1.1 200 OK
\r\n
"
mg_printf
(
conn
,
"HTTP/1.1 200 OK
\r\n
"
"Content-Length: %d
\r\n
"
"Content-Type: text/plain
\r\n\r\n
"
"Content-Type: text/plain
\r\n\r\n
"
"%s"
,
(
int
)
strlen
(
fetch_data
),
fetch_data
);
"%s"
,
fetch_data
);
close_connection
(
conn
);
return
1
;
return
1
;
}
}
...
@@ -298,6 +298,7 @@ static void test_mg_download(void) {
...
@@ -298,6 +298,7 @@ static void test_mg_download(void) {
free
(
p1
),
free
(
p2
);
free
(
p1
),
free
(
p2
);
mg_close_connection
(
conn
);
mg_close_connection
(
conn
);
// Fetch in-memory file, should succeed.
// Fetch in-memory file, should succeed.
ASSERT
((
conn
=
mg_download
(
"localhost"
,
port
,
1
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
ASSERT
((
conn
=
mg_download
(
"localhost"
,
port
,
1
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
"GET /blah HTTP/1.1
\r\n\r\n
"
))
!=
NULL
);
"GET /blah HTTP/1.1
\r\n\r\n
"
))
!=
NULL
);
...
@@ -307,6 +308,15 @@ static void test_mg_download(void) {
...
@@ -307,6 +308,15 @@ static void test_mg_download(void) {
free
(
p1
);
free
(
p1
);
mg_close_connection
(
conn
);
mg_close_connection
(
conn
);
// Fetch in-memory data with no Content-Length, should succeed.
ASSERT
((
conn
=
mg_download
(
"localhost"
,
port
,
1
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
"GET /data HTTP/1.1
\r\n\r\n
"
))
!=
NULL
);
ASSERT
((
p1
=
read_conn
(
conn
,
&
len1
))
!=
NULL
);
ASSERT
(
len1
==
(
int
)
strlen
(
fetch_data
));
ASSERT
(
memcmp
(
p1
,
fetch_data
,
len1
)
==
0
);
free
(
p1
);
mg_close_connection
(
conn
);
// Test SSL redirect, IP address
// Test SSL redirect, IP address
ASSERT
((
conn
=
mg_download
(
"localhost"
,
atoi
(
HTTP_PORT
),
0
,
ASSERT
((
conn
=
mg_download
(
"localhost"
,
atoi
(
HTTP_PORT
),
0
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
ebuf
,
sizeof
(
ebuf
),
"%s"
,
...
...
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