File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -133,16 +133,20 @@ namespace ix
133133 if (headers.find (" Content-Length" ) != headers.end ())
134134 {
135135 int contentLength = 0 ;
136- try
137136 {
138- contentLength = std::stoi (headers[" Content-Length" ]);
137+ const char * p = headers[" Content-Length" ].c_str ();
138+ char * p_end{};
139+ errno = 0 ;
140+ long val = std::strtol (p, &p_end, 10 );
141+ if (p_end == p // invalid argument
142+ || errno == ERANGE // out of range
143+ || val < std::numeric_limits<int >::min ()
144+ || val > std::numeric_limits<int >::max ()) {
145+ return std::make_tuple (
146+ false , " Error parsing HTTP Header 'Content-Length'" , httpRequest);
147+ }
148+ contentLength = val;
139149 }
140- catch (const std::exception&)
141- {
142- return std::make_tuple (
143- false , " Error parsing HTTP Header 'Content-Length'" , httpRequest);
144- }
145-
146150 if (contentLength < 0 )
147151 {
148152 return std::make_tuple (
You can’t perform that action at this time.
0 commit comments