Skip to content

Change binLen to pointer in hex2bin and base642bin - #84

Merged
gurpreet- merged 1 commit into
terl:masterfrom
ionspin:65-fix-param-instead-of-pointer
Oct 5, 2020
Merged

Change binLen to pointer in hex2bin and base642bin#84
gurpreet- merged 1 commit into
terl:masterfrom
ionspin:65-fix-param-instead-of-pointer

Conversation

@ionspin

@ionspin ionspin commented Sep 27, 2020

Copy link
Copy Markdown
Contributor

Libsodium hex2bin and base642bin expect a pointer to binLen and hexEnd/b64End parameters. Links to libsodium source:

The binLen values are needed to calcualte correct size after conversion.

the hexEnd and b64End values are used by libsodium to store pointers to the next byte after the last parsed byte. Since it was previously just a byte parameter, libsodium would treat it as a address and try to write to that adrress causing JVM to crash

...
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000007700000000

Register to memory mapping:

RAX=0x0 is NULL
RBX=0x00007fec0817973e points into unknown readable memory: 00 00
...

Also added tests to cover base64 and hex use cases.

This fixes #83

…ned is needed to trim the array, change hexEnd and b64End to pointers as well, as otherwise the JVM would crash when attempting to write to address supplied by the preiously primitive byte parameter
@gurpreet-
gurpreet- merged commit 6aa5903 into terl:master Oct 5, 2020
@gurpreet-

Copy link
Copy Markdown
Contributor

Wow, thank you so much for this! Thanks for the tests too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass-by-value instead of pointer parameter in base64 to bin and hex to bin functions

2 participants