Skip to content
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

Avoid stringop-overflow errors #10293

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

Conversation

keithc-ca
Copy link
Contributor

Rework code that sets thread name in trace buffer to avoid compiler errors, e.g.:

error: '__builtin_strncpy' writing 512 bytes into a region of size 1 overflows the destination

error: '__builtin_strncpy' writing 512 bytes into a region of size 1
overflows the destination

Signed-off-by: Keith W. Campbell <keithc@ca.ibm.com>
@keithc-ca
Copy link
Contributor Author

Tested by @knn-k - see #10278 (comment).

@knn-k
Copy link
Contributor

knn-k commented Jul 30, 2020

#4486 is the original issue with trclog.c and AArch64.

@knn-k
Copy link
Contributor

knn-k commented Jul 30, 2020

jenkins compile all jdk11

* target for strcpy, etc.: we want to avoid warnings due to the
* apparent lack of space (we've made sure there's enough room).
*/
recordThreadName = offsetof(UtTraceRecord, threadName) + (char *)(void *)&trcBuf->record;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to cast twice here? I don't think (void *) is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps not, but I think it's safer with the extra cast as it should make it clear to the compiler that there's no relationship between the pointer &trcBuf->record and the result of the casts.

Consider an analogy with Java: You'll get a compile error trying to cast a String to an Integer, but you can write (Integer)(Object)"oops" which compiles just fine (though you'll get a ClassCastException at runtime). The cast to Object is comparable to the cast to void * (and there's no exception in C).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this particular part of the change will be unnecessary once eclipse/omr#5444 is merged.

@Hello71
Copy link
Contributor

Hello71 commented Jul 31, 2020

this is not a correct solution. see #10244 (comment), #10244 (comment), #10299 (comment)

@keithc-ca
Copy link
Contributor Author

this is not a correct solution.

Please explain this assertion.

@genie-openj9
Copy link

Can one of the admins verify this patch?

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.

4 participants