Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/net/lib/libwg Paranoia: use strlcpy rather than str...



details:   https://anonhg.NetBSD.org/src/rev/a47907baff08
branches:  trunk
changeset: 937794:a47907baff08
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Aug 27 02:50:44 2020 +0000

description:
Paranoia: use strlcpy rather than strcpy here and detect truncation.

Not an issue for the one caller in tree, but let's not leave rakes to
step on.

diffstat:

 sys/rump/net/lib/libwg/wg_user.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (39 lines):

diff -r 14b941d9db83 -r a47907baff08 sys/rump/net/lib/libwg/wg_user.c
--- a/sys/rump/net/lib/libwg/wg_user.c  Thu Aug 27 01:52:04 2020 +0000
+++ b/sys/rump/net/lib/libwg/wg_user.c  Thu Aug 27 02:50:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: wg_user.c,v 1.1 2020/08/26 16:03:42 riastradh Exp $    */
+/*     $NetBSD: wg_user.c,v 1.2 2020/08/27 02:50:44 riastradh Exp $    */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wg_user.c,v 1.1 2020/08/26 16:03:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wg_user.c,v 1.2 2020/08/27 02:50:44 riastradh Exp $");
 
 #ifndef _KERNEL
 #include <sys/types.h>
@@ -243,13 +243,18 @@
                goto oerr1;
        }
 
+       if (strlcpy(wgu->wgu_tun_name, tun_name, sizeof(wgu->wgu_tun_name))
+           >= sizeof(wgu->wgu_tun_name)) {
+               rv = EINVAL;
+               goto oerr2;
+       }
+       wgu->wgu_sc = wg;
+
        wgu->wgu_fd = open_tun(tun_name);
        if (wgu->wgu_fd == -1) {
                rv = errno;
                goto oerr2;
        }
-       strcpy(wgu->wgu_tun_name, tun_name);
-       wgu->wgu_sc = wg;
 
        if (pipe(wgu->wgu_pipe) == -1) {
                rv = errno;



Home | Main Index | Thread Index | Old Index