Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Add a check before the memcpy. memcpy is defined to...



details:   https://anonhg.NetBSD.org/src/rev/c3e19c2399fa
branches:  trunk
changeset: 455325:c3e19c2399fa
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Oct 14 16:27:03 2019 +0000

description:
Add a check before the memcpy. memcpy is defined to never take NULL as
second argument, and the compiler is free to perform optimizations knowing
that this argument is never NULL.

In this particular case, it was harmless. But still good to fix.

Reported-by: syzbot+6f504255accb795eb6b7%syzkaller.appspotmail.com@localhost

diffstat:

 sys/kern/uipc_socket.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (29 lines):

diff -r 4db65a101166 -r c3e19c2399fa sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Mon Oct 14 14:48:48 2019 +0000
+++ b/sys/kern/uipc_socket.c    Mon Oct 14 16:27:03 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.284 2019/09/27 00:32:03 pgoyette Exp $       */
+/*     $NetBSD: uipc_socket.c,v 1.285 2019/10/14 16:27:03 maxv Exp $   */
 
 /*
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.284 2019/09/27 00:32:03 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.285 2019/10/14 16:27:03 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -2096,7 +2096,9 @@
        }
 
        sopt->sopt_retsize = MIN(sopt->sopt_size, len);
-       memcpy(sopt->sopt_data, buf, sopt->sopt_retsize);
+       if (sopt->sopt_retsize > 0) {
+               memcpy(sopt->sopt_data, buf, sopt->sopt_retsize);
+       }
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index