Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions quiche/balsa/header_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool HasInvalidHeaderChars(absl::string_view value) {
bool HasInvalidPathChar(absl::string_view value) {
static constexpr std::array<bool, 256> invalidCharTable =
buildInvalidPathCharLookupTable();
for (const char c : value) {
for (const uint8_t c : value) {
if (invalidCharTable[c]) {
Comment on lines +244 to 245

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Implicitly converting char to uint8_t in the range-based for loop can trigger compiler warnings (such as -Wsign-conversion or -Wconversion) in strict build environments. To prevent this and maintain consistency with other validators in this file (like IsValidToken and IsValidChunkExtension), it is better to iterate over const char c and perform an explicit static_cast<uint8_t>(c) when indexing the lookup table.

Suggested change
for (const uint8_t c : value) {
if (invalidCharTable[c]) {
for (const char c : value) {
if (invalidCharTable[static_cast<uint8_t>(c)]) {

return true;
}
Expand All @@ -252,7 +252,7 @@ bool HasInvalidPathChar(absl::string_view value) {
bool HasInvalidQueryChar(absl::string_view value) {
static constexpr std::array<bool, 256> invalidCharTable =
buildInvalidQueryCharLookupTable();
for (const char c : value) {
for (const uint8_t c : value) {
if (invalidCharTable[c]) {
Comment on lines +255 to 256

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Implicitly converting char to uint8_t in the range-based for loop can trigger compiler warnings (such as -Wsign-conversion or -Wconversion) in strict build environments. To prevent this and maintain consistency with other validators in this file (like IsValidToken and IsValidChunkExtension), it is better to iterate over const char c and perform an explicit static_cast<uint8_t>(c) when indexing the lookup table.

Suggested change
for (const uint8_t c : value) {
if (invalidCharTable[c]) {
for (const char c : value) {
if (invalidCharTable[static_cast<uint8_t>(c)]) {

return true;
}
Expand Down
10 changes: 10 additions & 0 deletions quiche/balsa/header_properties_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ TEST(HeaderPropertiesTest, HasInvalidPathChar) {
EXPECT_TRUE(HasInvalidPathChar("/path\rwith\tother\nwhitespace"));
EXPECT_TRUE(HasInvalidPathChar("/backtick`"));
EXPECT_TRUE(HasInvalidPathChar("/angle<brackets>also/bad"));
// Bytes >= 0x80 are not valid path characters and must be rejected
// without indexing the lookup table out of bounds.
EXPECT_TRUE(HasInvalidPathChar("/caf\xc3\xa9"));
EXPECT_TRUE(HasInvalidPathChar(std::string(1, '\x80')));
EXPECT_TRUE(HasInvalidPathChar(std::string(1, '\xff')));
}

TEST(HeaderPropertiesTest, HasInvalidQueryChar) {
Expand All @@ -143,6 +148,11 @@ TEST(HeaderPropertiesTest, HasInvalidQueryChar) {
EXPECT_TRUE(HasInvalidQueryChar("query with spaces"));
EXPECT_TRUE(HasInvalidQueryChar("query\rwith\tother\nwhitespace"));
EXPECT_TRUE(HasInvalidQueryChar("query_with_angle<brackets>also_bad"));
// Bytes >= 0x80 are not valid query characters and must be rejected
// without indexing the lookup table out of bounds.
EXPECT_TRUE(HasInvalidQueryChar("caf\xc3\xa9"));
EXPECT_TRUE(HasInvalidQueryChar(std::string(1, '\x80')));
EXPECT_TRUE(HasInvalidQueryChar(std::string(1, '\xff')));
}

TEST(HeaderPropertiesTest, IsValidTokenVsHasInvalidHeaderChars) {
Expand Down
Loading