Date: Wed, 25 May 2016 14:14:01 -0700 (PDT) From: Don Lewis <truckman@FreeBSD.org> To: ed@nuxi.nl Cc: freebsd-arch@freebsd.org Subject: Re: is ut_user[] in struct utmpx NUL terminated? Message-ID: <201605252114.u4PLE1NA007337@gw.catspoiler.org> In-Reply-To: <CABh_MKn20ABaQ=N2s44jscsDUZ6n2s8nWX5DdYa4jGNfUqAf=g@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 16 May, Ed Schouten wrote: > Hi Don, > > 2016-05-16 1:07 GMT+02:00 Don Lewis <truckman@freebsd.org>: >> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605252114.u4PLE1NA007337>