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
799cc369
Commit
799cc369
authored
9 years ago
by
Deomid Ryabkov
Committed by
Marko Mikulicic
9 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce stack usage when parsing HTTP URL
PUBLISHED_FROM=682f59e58d8335352cc09987a91e85cc264cf0f8
parent
b97d3fea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
14 deletions
+32
-14
mongoose.c
mongoose.c
+32
-14
No files found.
mongoose.c
View file @
799cc369
...
...
@@ -5969,9 +5969,10 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
const
char
*
url
,
const
char
*
extra_headers
,
const
char
*
post_data
)
{
struct
mg_connection
*
nc
;
char
addr
[
1100
],
path
[
4096
];
/* NOTE: keep sizes in sync with sscanf below */
int
use_ssl
=
0
,
addr_len
=
0
;
struct
mg_connection
*
nc
=
NULL
;
char
*
addr
=
NULL
;
const
char
*
path
=
NULL
;
int
use_ssl
=
0
,
addr_len
=
0
,
port_i
=
-
1
;
if
(
memcmp
(
url
,
"http://"
,
7
)
==
0
)
{
url
+=
7
;
...
...
@@ -5983,15 +5984,32 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
#endif
}
addr
[
0
]
=
path
[
0
]
=
'\0'
;
/* addr buffer size made smaller to allow for port to be prepended */
sscanf
(
url
,
"%1095[^/]/%4095s"
,
addr
,
path
);
if
(
strchr
(
addr
,
':'
)
==
NULL
)
{
addr_len
=
strlen
(
addr
);
strncat
(
addr
,
use_ssl
?
":443"
:
":80"
,
sizeof
(
addr
)
-
(
addr_len
+
1
));
while
(
*
url
!=
'\0'
)
{
addr
=
(
char
*
)
MG_REALLOC
(
addr
,
addr_len
+
5
/* space for port too. */
);
if
(
addr
==
NULL
)
{
DBG
((
"OOM"
));
return
NULL
;
}
if
(
*
url
==
'/'
)
{
url
++
;
break
;
}
if
(
*
url
==
':'
)
port_i
=
addr_len
;
addr
[
addr_len
++
]
=
*
url
;
addr
[
addr_len
]
=
'\0'
;
url
++
;
}
if
(
addr_len
==
0
)
goto
cleanup
;
if
(
port_i
<
0
)
{
port_i
=
addr_len
;
strcpy
(
addr
+
port_i
,
use_ssl
?
":443"
:
":80"
);
}
else
{
port_i
=
-
1
;
}
if
(
path
==
NULL
)
path
=
url
;
DBG
((
"%s %s"
,
addr
,
path
));
if
((
nc
=
mg_connect
(
mgr
,
addr
,
ev_handler
))
!=
NULL
)
{
mg_set_protocol_http_websocket
(
nc
);
...
...
@@ -6001,10 +6019,8 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
#endif
}
if
(
addr_len
)
{
/* Do not add port. See https://github.com/cesanta/mongoose/pull/304 */
addr
[
addr_len
]
=
'\0'
;
}
/* If the port was addred by us, restore the original host. */
if
(
port_i
>=
0
)
addr
[
port_i
]
=
'\0'
;
mg_printf
(
nc
,
"%s /%s HTTP/1.1
\r\n
Host: %s
\r\n
Content-Length: %"
SIZE_T_FMT
"
\r\n
%s
\r\n
%s"
,
post_data
==
NULL
?
"GET"
:
"POST"
,
path
,
addr
,
...
...
@@ -6013,6 +6029,8 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
post_data
==
NULL
?
""
:
post_data
);
}
cleanup:
MG_FREE
(
addr
);
return
nc
;
}
...
...
This diff is collapsed.
Click to expand it.
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