Re: [PATCH] selftests: net: ipmr: Avoid memcpy() from NULL in nl_add_rtattr()
From: Kuniyuki Iwashima
Date: Tue Sep 01 2026 - 19:50:52 EST
On Tue, Sep 1, 2026 at 12:14 AM Chaithanya Lagisetty
<nagachaithanya9911@xxxxxxxxx> wrote:
>
> nl_add_rtattr() unconditionally does memcpy(RTA_DATA(rta), data, len).
> For zero-length attributes the callers pass data == NULL and len == 0,
> for example the RTA_PREFSRC attribute added for proxy MFC entries:
>
> if (mfc_attr->proxy)
> rta = nl_add_rtattr(nlmsg, rta, RTA_PREFSRC, NULL, 0);
>
> Passing a NULL pointer to memcpy() is undefined behaviour even when the
> length is zero, because its source parameter is marked
> __attribute__((nonnull)); it is flagged by fortify/-Wnonnull.
It's not flagged since NULL is passed via nl_add_rtattr(), not directly
to memcpy().
Also, the behaviour will be well-defined with N3322 in C2y.
Given there is no real harm and we do not bother revisiting this,
there is no need to change that.