From dd9efb7e7e020e69f3379a6a2cc6285d64b9db76 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 17 Mar 2004 09:32:18 +0000 Subject: [PATCH] Merge FreeBSD ifconfig.c rev 1.94, strlcpy() cannot be used if the source string is not terminated. This is a clean rewrite of the (minor) patch and not a direct MFC. Reminded-by: Brooks Davis --- sbin/ifconfig/ifconfig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index cf9b64e4fb..c75b99b6e9 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved. * @(#)ifconfig.c 8.2 (Berkeley) 2/16/94 * $FreeBSD: src/sbin/ifconfig/ifconfig.c,v 1.96 2004/02/27 06:43:14 kan Exp $ - * $DragonFly: src/sbin/ifconfig/ifconfig.c,v 1.8 2004/03/17 02:18:23 dillon Exp $ + * $DragonFly: src/sbin/ifconfig/ifconfig.c,v 1.9 2004/03/17 09:32:18 dillon Exp $ */ #include @@ -595,9 +595,13 @@ main(int argc, char * const *argv) next += nextifm->ifm_msglen; } if (all || namesonly) { - strlcpy(name, sdl->sdl_data, - sizeof(name) <= sdl->sdl_nlen ? - sizeof(name) : sdl->sdl_nlen + 1); + int len; + + /* sdl_data may not be terminated, don't use strlcpy */ + if ((len = sdl->sdl_nlen) > sizeof(name) - 1) + len = sizeof(name) - 1; + bcopy(sdl->sdl_data, name, len); + name[len] = 0; if (uponly) if ((flags & IFF_UP) == 0) -- 2.41.0