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 claims the generated code has UB #18

Open
stsp opened this issue May 13, 2024 · 2 comments
Open

ubsan claims the generated code has UB #18

stsp opened this issue May 13, 2024 · 2 comments

Comments

@stsp
Copy link

stsp commented May 13, 2024

I have this rpc template file:
https://github.com/dosemu2/dosemu2/blob/6af6ea929550e00563223575a3f9bf007927ba75/src/base/lib/fsrpc/fsrpc.x
on which I do rpcgen -N -M fsrpc.x.
If compiled with clang -fsanitize=undefined,
then on start-up I am getting this:

fsrpc_svc1.c:210:20: runtime error: call to function _add_path_1 through pointer to incorrect function type 'int (*)(char *, void *, struct svc_req *)'
/home/stas/src/dosemu2-suid/src/base/lib/fsrpc/fsrpc_svc1.c:23:25: note: _add_path_1 defined here

The generated function looks like this:

int
_add_path_1 (char * *argp, void *result, struct svc_req *rqstp)
{
        return (add_path_1_svc(*argp, result, rqstp));
}

The problematic spot is:
retval = (bool_t) (*local)((char *)&argument, (void *)&result, rqstp);

local is defined as:
bool_t (*local)(char *, void *, struct svc_req *);

I believe ubsan dislikes the fact that
the function has char ** as the first
arg, but is called via the pointer which
has char * as a first arg. If I change
the definition of local to use char **
then this function no longer results in
UB, but all others do, as they only have
a single pointer in the first arg.

stsp added a commit to dosemu2/dosemu2 that referenced this issue May 13, 2024
clang's ubsan doesn't like the generated code, gcc is OK.
I don't know if the UB is real or not, so for now disable only
clang's sanitizer, assuming it is a false-positive.

See thkukuk/rpcsvc-proto#18

Also disable unused variable warnings, as the generated code
has unused variables.
@thkukuk
Copy link
Owner

thkukuk commented May 14, 2024

RPC is over 40 years old and deprecated since at mininum 2 decades. It's no surprise that modern compilers don't like that old, autogenerated code anymore.

Adjust the autogenerated code so that modern compilers like it again and don't re-generate them anymore. And look for something better than RPC.

@stsp
Copy link
Author

stsp commented May 14, 2024

What is "better than RPC"?
I think I can take a look into searpc
as it looks quite simple, but its still
an rpc, so I am not sure if it qualifies.

stsp added a commit to dosemu2/dosemu2 that referenced this issue Jun 19, 2024
clang's ubsan doesn't like the generated code, gcc is OK.
I don't know if the UB is real or not, so for now disable only
clang's sanitizer, assuming it is a false-positive.

See thkukuk/rpcsvc-proto#18

Also disable unused variable warnings, as the generated code
has unused variables.
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

No branches or pull requests

2 participants