-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Create decoder for HTML entities #44
Conversation
} | ||
|
||
// Append the decoded byte | ||
decoded = append(decoded, byte(num)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 2 months ago
To fix the problem, we need to ensure that the integer value parsed from the string is within the valid range for a byte
(0-255) before performing the conversion. This can be done by adding a bounds check after parsing the integer and before converting it to a byte
.
- Parse the integer using
strconv.Atoi
. - Check if the parsed integer is within the range of 0 to 255.
- If the integer is within the valid range, convert it to a
byte
. - If the integer is outside the valid range, handle the error appropriately (e.g., skip the conversion or use a default value).
-
Copy modified lines R111-R115
@@ -110,4 +110,7 @@ | ||
|
||
// Append the decoded byte | ||
decoded = append(decoded, byte(num)) | ||
// Check if the parsed number is within the valid range for a byte | ||
if num >= 0 && num <= 255 { | ||
// Append the decoded byte | ||
decoded = append(decoded, byte(num)) | ||
} | ||
|
} | ||
|
||
// Append the decoded byte | ||
decoded = append(decoded, byte(num)) |
Check failure
Code scanning / CodeQL
Incorrect conversion between integer types
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 2 months ago
To fix the problem, we need to ensure that the parsed integer value is within the valid range for a byte
(0 to 255) before performing the conversion. This can be done by adding a bounds check after parsing the integer and before converting it to a byte
.
- We will add a check to ensure that the parsed integer is within the range of 0 to 255.
- If the parsed integer is outside this range, we will skip the conversion and continue with the next match.
- This change will be made in the
decodeHtmlHex
function in the filepkg/decoders/html_entity.go
.
-
Copy modified lines R145-R149
@@ -144,2 +144,7 @@ | ||
|
||
// Check if the parsed number is within the valid range for a byte | ||
if num < 0 || num > 255 { | ||
continue | ||
} | ||
|
||
// Append the decoded byte |
cb4c962
to
6083804
Compare
Description:
Motivation: trufflesecurity#2231
Checklist:
make test-community
)?make lint
this requires golangci-lint)?