-
Notifications
You must be signed in to change notification settings - Fork 680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for out of bound read in std::strtol while parsing HTTP requests #1208
Open
alexprabhat99
wants to merge
5
commits into
pistacheio:master
Choose a base branch
from
alexprabhat99:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f28567
std::from_chars changes in http_header.cc
alexprabhat99 51f0993
std::from_chars changes in http.cc
alexprabhat99 ae776d0
std::from_chars changes in net.cc
alexprabhat99 1bae11f
updated version.txt
alexprabhat99 93c1f2b
Merge branch 'master' into master
kiplingw File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ | |||||||
#include <sys/stat.h> | ||||||||
#include <sys/types.h> | ||||||||
#include <unistd.h> | ||||||||
#include <charconv> | ||||||||
|
||||||||
namespace Pistache::Http | ||||||||
{ | ||||||||
|
@@ -287,9 +288,18 @@ namespace Pistache::Http | |||||||
if (!match_until(' ', cursor)) | ||||||||
return State::Again; | ||||||||
|
||||||||
char* end; | ||||||||
auto code = strtol(codeToken.rawText(), &end, 10); | ||||||||
if (*end != ' ') | ||||||||
const char* beg = codeToken.rawText(); | ||||||||
const char* beg_trim = beg; | ||||||||
while (*beg_trim == '+' || *beg_trim == ' ') | ||||||||
{ | ||||||||
if (*(beg_trim + 1)) | ||||||||
++beg_trim; | ||||||||
} | ||||||||
std::string_view view(beg_trim, codeToken.size()); | ||||||||
const char* end = view.data() + view.size(); | ||||||||
long code = 0; | ||||||||
auto res = std::from_chars(beg_trim, end, code); | ||||||||
if (*res.ptr != ' ') | ||||||||
raise("Failed to parse return code"); | ||||||||
response->code_ = static_cast<Http::Code>(code); | ||||||||
|
||||||||
|
@@ -455,10 +465,18 @@ namespace Pistache::Http | |||||||
if (!cursor.advance(1)) | ||||||||
return Incomplete; | ||||||||
|
||||||||
char* end; | ||||||||
const char* raw = chunkSize.rawText(); | ||||||||
auto sz = std::strtol(raw, &end, 16); | ||||||||
if (*end != '\r') | ||||||||
const char* beg = chunkSize.rawText(); | ||||||||
const char* beg_trim = beg; | ||||||||
while (*beg_trim == '+' || *beg_trim == ' ') | ||||||||
{ | ||||||||
if (*(beg_trim + 1)) | ||||||||
++beg_trim; | ||||||||
} | ||||||||
std::string_view view = beg_trim; | ||||||||
const char* end = view.data() + view.size(); | ||||||||
Comment on lines
+475
to
+476
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm generally a fan of string_view, but here I personally find it unnecessary. I'd suggest using
Suggested change
|
||||||||
long sz = 0; | ||||||||
auto res = std::from_chars(beg_trim, end, sz, 16); | ||||||||
if (*res.ptr != '\r') | ||||||||
throw std::runtime_error("Invalid chunk size"); | ||||||||
|
||||||||
// CRLF | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.9.20240421 | ||
0.2.10.20240426 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is a string_view being used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Citing cppreference:
So isn't your code exactly the same as: