Skip to content

fix/minor: Error encoding hexa decimal #2068

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

Closed
wants to merge 1 commit into from
Closed

fix/minor: Error encoding hexa decimal #2068

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 15, 2019

String is defined as an array of char. The char can be negative. The
cast "reinterpret_cast" from char to int keep the negative side, so
the "unsigned char" number 0x91 is negative as "char". When it is
"reinterpret_cast" as integer, it becomes 0xffffff91, so the hexadecimal
display is broken:

[155493246391.747672] [/absolute?what=badarg2] [9] T (0) t:hexEncode: "ffffff91ffffffecffffffe6334bffffffebffffff87ffffff9affffff824a06ffffffc33b4cffff (14 characters omitted)"

This patch fix this behavior using classic cast without reinterpret_cast:

[155493251286.221115] [/absolute?what=badarg2] [9] T (0) t:hexEncode: "91ece6334beb879a824a06c33b4cb4240e4c6f56"

String is defined as an array of char. The char can be negative. The
cast "reinterpret_cast" from char to int keep the negative side, so
the "unsigned char" number 0x91 is negative as "char". When it is
"reinterpret_cast" as integer, it becomes 0xffffff91, so the hexadecimal
display is broken:

   [155493246391.747672] [/absolute?what=badarg2] [9]  T (0) t:hexEncode: "ffffff91ffffffecffffffe6334bffffffebffffff87ffffff9affffff824a06ffffffc33b4cffff (14 characters omitted)"

This patch fix this behavior using classic cast without reinterpret_cast:

   [155493251286.221115] [/absolute?what=badarg2] [9]  T (0) t:hexEncode: "91ece6334beb879a824a06c33b4cb4240e4c6f56"
@victorhora victorhora added 3.x Related to ModSecurity version 3.x enhancement pr available labels Apr 15, 2019
@victorhora victorhora added this to the v3.0.4 milestone Apr 15, 2019
zimmerle added a commit that referenced this pull request May 27, 2019
@zimmerle
Copy link
Contributor

Hi @tech-ozon-io,

Thank you for your contribution. Sorry, for the delay. The code is now merged!

@zimmerle zimmerle closed this May 27, 2019
vladbukin pushed a commit to vladbukin/ModSecurity that referenced this pull request Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Related to ModSecurity version 3.x enhancement pr available
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants