Date: Thu, 21 Apr 2016 19:33:55 +0200 From: Hans Petter Selasky <hps@selasky.org> To: Alan Somers <asomers@freebsd.org>, Ngie Cooper <yaneurabeya@gmail.com> Cc: "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r298420 - head/sys/geom Message-ID: <57190F03.2080703@selasky.org> In-Reply-To: <CAOtMX2gBGnuLKRxefreCsSvjRr8RzZND7S4%2BxWA0f7AEB_ZziQ@mail.gmail.com> References: <201604211643.u3LGhFpR057982@repo.freebsd.org> <CAGHfRMCj5zQUHddyoY8Vn2qxJyjV7sUHYDK%2B0Jg2SCCiFX6_Sw@mail.gmail.com> <CAGHfRMBm5RtfC8qk17snHvzEDchh0miizWOqR1srH_cFt7rb9Q@mail.gmail.com> <CAOtMX2gBGnuLKRxefreCsSvjRr8RzZND7S4%2BxWA0f7AEB_ZziQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 04/21/16 19:26, Alan Somers wrote: > On Thu, Apr 21, 2016 at 11:09 AM, Ngie Cooper <yaneurabeya@gmail.com> wrote: > >> On Thu, Apr 21, 2016 at 10:08 AM, Ngie Cooper <yaneurabeya@gmail.com> >> wrote: >>> On Thu, Apr 21, 2016 at 9:43 AM, Alan Somers <asomers@freebsd.org> >>>> { >>>> struct g_geom *gp; >>>> struct g_provider *pp; >>>> + char devnamebuf[128]; >>> >>> Why 128? Also, why not sbuf? >>> >>>> gp = dp->d_geom; >>>> if (gp != NULL) >>>> LIST_FOREACH(pp, &gp->provider, provider) >>>> (void)g_attr_changed(pp, attr, flag); >>>> + snprintf(devnamebuf, 128, "devname=%s%d", dp->d_name, >> dp->d_unit); >>> >>> Why not sizeof(devnamebuf) ? >> >> Also: this doesn't NUL terminate devnamebuf; it really should >> (otherwise, boom... crash in geom)... >> > > snprintf(3) says "The output is always null-terminated." and it looks like > the kernel version does the same thing at subr_prf.c:560. Am I missing > something? > Hi, The code is correct, though it is good practice to use sizeof() like Ngie suggests or define the size of the buffer like a macro. grep -rE "snprintf.*sizeof" /usr/src/sys/dev --HPS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?57190F03.2080703>