From owner-cvs-all@FreeBSD.ORG Fri Dec 2 16:17:58 2005 Return-Path: X-Original-To: cvs-all@FreeBSD.org Delivered-To: cvs-all@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C79FA16A41F; Fri, 2 Dec 2005 16:17:58 +0000 (GMT) (envelope-from gad@FreeBSD.org) Received: from smtp1.server.rpi.edu (smtp1.server.rpi.edu [128.113.2.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id 54CE543D5C; Fri, 2 Dec 2005 16:17:58 +0000 (GMT) (envelope-from gad@FreeBSD.org) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by smtp1.server.rpi.edu (8.13.0/8.13.0) with ESMTP id jB2GHT1d006578; Fri, 2 Dec 2005 11:17:29 -0500 Mime-Version: 1.0 Message-Id: In-Reply-To: <200512021457.jB2EvWbr075948@ambrisko.com> References: <200512021457.jB2EvWbr075948@ambrisko.com> Date: Fri, 2 Dec 2005 11:17:28 -0500 To: Doug Ambrisko , Pawel Jakub Dawidek From: Garance A Drosehn Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-CanItPRO-Stream: default X-RPI-SA-Score: undef - spam-scanning disabled X-Scanned-By: CanIt (www . canit . ca) on 128.113.2.1 Cc: Doug Ambrisko , src-committers@FreeBSD.org, cvs-all@FreeBSD.org, cvs-src@FreeBSD.org Subject: Re: cvs commit: src Makefile.inc1 src/lib/libc/gen __xuname.c getosreldate.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Dec 2005 16:17:59 -0000 At 6:57 AM -0800 12/2/05, Doug Ambrisko wrote: >Pawel Jakub Dawidek writes: >| [...] >| +> name->sysname[sizeof(name->sysname) - 1] = '\0'; >| +> + if ((p = getenv("UNAME_s"))) >| +> + strncpy(name->sysname, p, sizeof(name->sysname)); >| [...] >| +> name->release[sizeof(name->release) - 1] = '\0'; >| +> + if ((p = getenv("UNAME_r"))) >| +> + strncpy(name->release, p, sizeof(name->release)); >| [...] >| +> + if ((p = getenv("UNAME_v"))) >| +> + strncpy(name->version, p, sizeof(name->version)); >| [...] >| +> name->machine[sizeof(name->machine) - 1] = '\0'; >| +> + if ((p = getenv("UNAME_m"))) >| +> + strncpy(name->machine, p, sizeof(name->machine)); >| >| As you can see, previous code tried to NULL-terminate buffer >| copied using strncpy(3) properly and you inserted your changes >| after these terminations. Please, NULL-terminate the buffers >| after using strncpy(3). > >The prior code had to NULL-terminate by hand since the data could >come from the sysctl not NULL-terminate. I thought the strncpy >would NULL-terminate but you are correct. strncpy is meant for strings where you don't want null-termination (such as fixed-length fields in structs). It was not meant for situations like this. Code like this should use strlcpy() instead. -- Garance Alistair Drosehn = gad@gilead.netel.rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA