-
Notifications
You must be signed in to change notification settings - Fork 142
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
Fix ASAN errors due adding offset to nullptr #240
base: master
Are you sure you want to change the base?
Conversation
utf8proc.c
Outdated
if (!dst){ | ||
written += utf8proc_decompose_char(entry_cp, dst, | ||
(bufsize > written) ? (bufsize - written) : 0, options, | ||
last_boundclass); | ||
}else{ | ||
written += utf8proc_decompose_char(entry_cp, dst+written, | ||
(bufsize > written) ? (bufsize - written) : 0, options, | ||
last_boundclass); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe cleaner to combine into a single call with a dst ? ...
argument
if (!dst){ | |
written += utf8proc_decompose_char(entry_cp, dst, | |
(bufsize > written) ? (bufsize - written) : 0, options, | |
last_boundclass); | |
}else{ | |
written += utf8proc_decompose_char(entry_cp, dst+written, | |
(bufsize > written) ? (bufsize - written) : 0, options, | |
last_boundclass); | |
} | |
written += utf8proc_decompose_char(entry_cp, | |
dst ? dst+written : dst, | |
(bufsize > written) ? (bufsize - written) : 0, options, | |
last_boundclass); |
(Note that the ASAN warning is harmless in this case, since |
Actually it's not just about the warning. I have noticed runtime error caused due to this that makes the program crash. |
This reverts commit b933f42.
Could you elaborate? I don't see any |
@stevengj This is my rough understanding what's going on: When utf8proc_decompose_custom is called here Line 736 in 63f31c9
applying non-zero offset 4 to null pointer . By incorporating changes in this PR, I could get rid of these run-time errors.
|
That sounds like a runtime error caused by ASAN. Applying a nonzero offset to a null pointer is perfectly safe if you never dereference the pointer. |
Answers to this question suggest that it's a UB. Although I'm not sure how come NULL pointer is "a pointer into, or just beyond, an array object", but clang generates an undefined behaviour error for this which suggest it might be a valid interpretation. |
This PR fixes the error when Address Sanitization is enabled. The offset is added to nullptr which gives following runtime error:
The PR checks whether the pointer is nullptr, and if so do not add offset to it.