Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2023 19:38:22 GMT
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d9f07162932b - releng/13.2 - netlink: do not memcpy 0 bytes from a NULL pointer
Message-ID:  <202303061938.326JcMjG020347@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/13.2 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=d9f07162932b3f34c9b1b2883773f580c0b04768

commit d9f07162932b3f34c9b1b2883773f580c0b04768
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-03-06 16:30:26 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-03-06 19:37:56 +0000

    netlink: do not memcpy 0 bytes from a NULL pointer
    
    Although it works in practice it is UB, and might break after a future
    compiler update.
    
    This was rewritten in main and the memcpy call no longer exists, so this
    is a direct commit to stable/13 before 055776c84a41 is MFC'd.
    
    Discussed with: melifaro
    Approved by:    re (cperciva)
    Sponsored by: The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D38927
    
    (cherry picked from commit 305aaa93e0c805294c8bcbb5fe8b9f7caa28b349)
---
 sys/netlink/route/iface.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c
index 96f21a79a369..3ddef06bed7e 100644
--- a/sys/netlink/route/iface.c
+++ b/sys/netlink/route/iface.c
@@ -458,8 +458,11 @@ rtnl_handle_getlink(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *n
 					error = ENOMEM;
 					break;
 				}
-				memcpy(new_array, match_array, offset * sizeof(void *));
-				free(match_array, M_TEMP);
+				if (match_array != NULL) {
+					memcpy(new_array, match_array,
+					    offset * sizeof(void *));
+					free(match_array, M_TEMP);
+				}
 				match_array = new_array;
 			}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202303061938.326JcMjG020347>