Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add ASan and UBSan to CI #161

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChillerDragon
Copy link

When built with UndefinedBehaviorSanitizer and AddressSanitizer the tests throw this UndefinedBehaviorSanitizer error

 json.c:437:34: runtime error: applying non-zero offset 8 to null pointer
    #0 0x4caab2 in json_parse_ex /home/runner/work/json-parser/json-parser/json.c:437:34
    #1 0x4daf8c in json_test /home/runner/work/json-parser/json-parser/tests/test.c:79:18
    #2 0x4da892 in json_verify /home/runner/work/json-parser/json-parser/tests/test.c:153:14
    #3 0x4d9fe2 in main /home/runner/work/json-parser/json-parser/tests/test.c:229:12
    #4 0x7f148b3dc0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)
    #5 0x41c2fd in _start (/home/runner/work/json-parser/json-parser/json-test+0x41c2fd)

Should be fixed first then this CI could help making sure it wont happen again 🙂

@DimitriPapadopoulos
Copy link
Contributor

Line 437 looks like this:

                        chars[0] += string_length + 1;

I understand that:

  • chars[0] is a null pointer,
  • string_length + 1 is the "non-zero offset 8".

Not sure I understand everything at this point, I need to run json-test in a debugger to grasp what this is about.

@DimitriPapadopoulos
Copy link
Contributor

DimitriPapadopoulos commented Aug 25, 2022

Also, how to reproduce the error you are referring to?

OK, I think I am able to reproduce it by running test_json on tests/valid-0003.json. Adding

                        printf("%p += %u\n", chars[0], string_length + 1);

to the source code yields:

(nil) += 4
0x4 += 4

But then, why would this necessarily be an actual error?

@ChillerDragon
Copy link
Author

But then, why would this necessarily be an actual error?

Adding to a null pointer is undefined behavior. Its good style to not go off standard.

@DimitriPapadopoulos
Copy link
Contributor

Ah right. I guess the code will have to be changed to:

chars[0] = (void*) ((uintptr_t) chars[0] + string_length + 1)

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.

2 participants