NFS: Do not memcpy from NULL when encoding an empty opaque #112

Merged
vitalif merged 1 commits from koolkhel/vitastor:ubsan-xdr-empty-opaque into master 2026-10-28 00:10:44 +03:00
Contributor

Description

xdr_bytes() copied data->size bytes from data->data even when the size was 0, and an empty opaque (for example the AUTH_NONE verifier of every RPC reply) has a NULL data pointer. memcpy() with a NULL source is undefined behaviour even for 0 bytes; UBSan (-fsanitize=undefined) stops the NFS server at its first reply.

Tested: a small program that encodes an empty opaque through xdr_impl.cpp, built with -fsanitize=undefined -fno-sanitize-recover=all, stops on master with xdr_impl_inline.h:162:19: runtime error: null pointer passed as argument 2 and runs clean with this commit. vitastor-nfs builds.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description xdr_bytes() copied data->size bytes from data->data even when the size was 0, and an empty opaque (for example the AUTH_NONE verifier of every RPC reply) has a NULL data pointer. memcpy() with a NULL source is undefined behaviour even for 0 bytes; UBSan (-fsanitize=undefined) stops the NFS server at its first reply. Tested: a small program that encodes an empty opaque through `xdr_impl.cpp`, built with `-fsanitize=undefined -fno-sanitize-recover=all`, stops on master with `xdr_impl_inline.h:162:19: runtime error: null pointer passed as argument 2` and runs clean with this commit. `vitastor-nfs` builds. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-10-27 10:26:34 +03:00
xdr_bytes() copied data->size bytes from data->data even when the size
was 0, and an empty opaque (for example the AUTH_NONE verifier of every
RPC reply) has a NULL data pointer. memcpy() with a NULL source is
undefined behaviour even for 0 bytes; UBSan (-fsanitize=undefined)
stops the NFS server at its first reply.
vitalif merged commit c0d6a417ba into master 2026-10-28 00:10:44 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#112
No description provided.