From owner-freebsd-arch@freebsd.org Wed May 25 21:14:11 2016 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9DE18B4AC7D for ; Wed, 25 May 2016 21:14:11 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org (unknown [IPv6:2602:304:b010:ef20::f2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gw.catspoiler.org", Issuer "gw.catspoiler.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 8073818B5 for ; Wed, 25 May 2016 21:14:11 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.15.2/8.15.2) with ESMTP id u4PLE1NA007337; Wed, 25 May 2016 14:14:07 -0700 (PDT) (envelope-from truckman@FreeBSD.org) Message-Id: <201605252114.u4PLE1NA007337@gw.catspoiler.org> Date: Wed, 25 May 2016 14:14:01 -0700 (PDT) From: Don Lewis Subject: Re: is ut_user[] in struct utmpx NUL terminated? To: ed@nuxi.nl cc: freebsd-arch@freebsd.org In-Reply-To: MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 May 2016 21:14:11 -0000 On 16 May, Ed Schouten wrote: > Hi Don, > > 2016-05-16 1:07 GMT+02:00 Don Lewis : >> There is a lot of code that expects ut_user[] to be NUL terminated. > > Our implementation of utmpx should be pretty friendly to use: > > - You can call pututxline() with strings that are not null terminated. > - The getutx*() functions return entries in which all strings are null > terminated. The latter doesn't appear to be true. If I stuff a non-NUL terminated 32 character user name into ut_user and then call pututxline(), it calls utx_to_futx(), which uses the UTOF_STRING() macro, which in turn uses snprintf() to copy the data to the corresponding field in a struct futx before saving the latter. Going in the other direction, getutxent() calls futx_to_utx(), which uses the FTOU_STRING() macro, which in turn uses strncpy() to copy the data back out. If the original name was 32 characters, then the ut_user value in the returned struct utmpx will not be NUL terminated.