Skip to content

Commit 20460a9

Browse files
authored
This corrects two instances of unsafe C++ code. (#33)
1 parent 3d1228c commit 20460a9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/parser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,10 @@ namespace ada::parser {
10061006
// and append the result to url’s path.
10071007
if (pointer != pointer_end) {
10081008
if (character_sets::bit_at(character_sets::C0_CONTROL_PERCENT_ENCODE, *pointer)) {
1009-
url.path += character_sets::hex + *pointer * 4;
1009+
// We cast to an unsigned 8-bit integer because
1010+
// *pointer is of type 'char' which may be signed or unsigned.
1011+
// A negative index access in 'character_sets::hex' is unsafe.
1012+
url.path += character_sets::hex[uint8_t(*pointer) * 4];
10101013
} else {
10111014
url.path += *pointer;
10121015
}
@@ -1177,7 +1180,7 @@ namespace ada::parser {
11771180
// a Windows drive letter and base’s path[0] is a normalized Windows drive letter,
11781181
// then append base’s path[0] to url’s path.
11791182
if (std::distance(pointer, pointer_end) > 0 && !base_url->path.empty()) {
1180-
if (!checkers::is_windows_drive_letter(pointer + pointer[0])) {
1183+
if (!checkers::is_windows_drive_letter({pointer, size_t(pointer_end - pointer)})) {
11811184
std::string first_base_url_path = base_url->path.substr(1, base_url->path.find_first_of('/', 1));
11821185

11831186
if (checkers::is_normalized_windows_drive_letter(first_base_url_path)) {

0 commit comments

Comments
 (0)