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

ubsan complains on rpcgen-generated code, gcc's one silent #92108

Open
stsp opened this issue May 14, 2024 · 5 comments
Open

ubsan complains on rpcgen-generated code, gcc's one silent #92108

stsp opened this issue May 14, 2024 · 5 comments
Labels
compiler-rt:ubsan Undefined behavior sanitizer

Comments

@stsp
Copy link

stsp commented May 14, 2024

It appears, clang's ubsan complains on
an rpcgen-generated code, while gcc's
ubsan is silent.
The code roughly looks like this (reduced test-case):

#include <stddef.h>

struct svc_req;

static int
_a_1 (void *argp, void *result, struct svc_req *rqstp)
{
        return 0;
}

int main()
{
        int (*local)(char *, void *, struct svc_req *);
        local = (int (*) (char *, void *,  struct svc_req *))_a_1;
        return local(NULL, NULL, NULL);
}

Now do this:

$ gcc -Wall -fsanitize=undefined tst.c 
$ ./a.out
$ clang -Wall -fsanitize=undefined tst.c 
$ ./a.out
tst.c:15:9: runtime error: call to function _a_1 through pointer to incorrect function type 'int (*)(char *, void *, struct svc_req *)'
tst.c: note: _a_1 defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tst.c:15:9

As can be seen, only clang complained.
I don't know if it is a real UB or a false-positive.
But as gcc keeps silence, I assume this is
a false-positive.
There is no way to "just fix" the code, as it
is generated by rpcgen.

@DimitryAndric
Copy link
Collaborator

I think UBSan is correct: _a_1 is defined with a char ** as its first argument, but the call is done with a char * as its first argument. Does the runtime error go away if you fix that?

@stsp
Copy link
Author

stsp commented May 14, 2024

It does, but if, for example, I change
char ** to void * in _a_1, then error
does NOT disappear.
So its not like clang's ubsan wants the
proper pointer indirection, no, it wants
the precise type match. Even void *
doesn't match to char *.

@stsp
Copy link
Author

stsp commented May 14, 2024

I edited the original example to use
void * instead of char **.

@EugeneZelenko EugeneZelenko added compiler-rt:ubsan Undefined behavior sanitizer and removed new issue labels May 14, 2024
@pinskia
Copy link

pinskia commented May 19, 2024

GCC does not currently implements the function mismatch specific UBSAN case yet.

@stsp
Copy link
Author

stsp commented May 19, 2024

So the UB is real and the ticket should
be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:ubsan Undefined behavior sanitizer
Projects
None yet
Development

No branches or pull requests

4 participants