Date: Sun, 21 Feb 2016 15:51:03 -0600 From: Benjamin Kaduk <bjkfbsd@gmail.com> To: Ian Lepore <ian@freebsd.org> Cc: Sean Bruno <sbruno@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, svn-src-projects@freebsd.org Subject: Re: svn commit: r295812 - projects/mips64-clang/sys/mips/rmi Message-ID: <CAJ5_RoCoJt8kbWvwvpPMYCDzM56qJjzrm54a=EfwesT-1fdz2A@mail.gmail.com> In-Reply-To: <1456066063.1294.40.camel@freebsd.org> References: <201602191637.u1JGb6lm055074@repo.freebsd.org> <1456066063.1294.40.camel@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Feb 21, 2016 at 8:47 AM, Ian Lepore <ian@freebsd.org> wrote: > On Fri, 2016-02-19 at 16:37 +0000, Sean Bruno wrote: > > Author: sbruno > > Date: Fri Feb 19 16:37:06 2016 > > New Revision: 295812 > > URL: https://svnweb.freebsd.org/changeset/base/295812 > > > > Log: > > Change a static const string to a #define as the strcpy() throws a > > warn/error with clang. > > > > /home/sbruno/mips64-clang/sys/mips/rmi/xls_ehci.c:133:25: error: > > format string is not a string literal (potentially insecure) > > [-Werror,-Wformat-security] > > sprintf(sc->sc_vendor, xlr_vendor_desc); > > > > Modified: > > projects/mips64-clang/sys/mips/rmi/xls_ehci.c > > > > Modified: projects/mips64-clang/sys/mips/rmi/xls_ehci.c > > ===================================================================== > > ========= > > --- projects/mips64-clang/sys/mips/rmi/xls_ehci.c Fri Feb 19 > > 15:53:08 2016 (r295811) > > +++ projects/mips64-clang/sys/mips/rmi/xls_ehci.c Fri Feb 19 > > 16:37:06 2016 (r295812) > > @@ -73,7 +73,7 @@ static device_attach_t ehci_xls_attach; > > static device_detach_t ehci_xls_detach; > > > > static const char *xlr_usb_dev_desc = "RMI XLR USB 2.0 controller"; > > -static const char *xlr_vendor_desc = "RMI Corp"; > > +#define XLR_VENDOR_DESC "RMI Corp"; > > > > static int > > ehci_xls_probe(device_t self) > > @@ -130,7 +130,7 @@ ehci_xls_attach(device_t self) > > device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus); > > device_set_desc(sc->sc_bus.bdev, xlr_usb_dev_desc); > > > > - sprintf(sc->sc_vendor, xlr_vendor_desc); > > + sprintf(sc->sc_vendor, XLR_VENDOR_DESC); > > > > err = bus_setup_intr(self, sc->sc_irq_res, > > INTR_TYPE_BIO | INTR_MPSAFE, NULL, > > > > Bah. The compiler should understand that a static const char* is > equivelent to a string literal for the purposes of this warning. > > Is it? The compiler would need to check that nothing else in the file writes to xlr_vendor_desc before making that conclusion; on the other hand, if it was char const * const, then that alone would suffice. > That said, a sprintf() is just a strange spelling of strlcpy() here. > Almost. sprintf() is not as good about length checking as strlcpy(), which is a much better option here, as you note. -Ben > > -- Ian > > _______________________________________________ > svn-src-projects@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/svn-src-projects > To unsubscribe, send any mail to "svn-src-projects-unsubscribe@freebsd.org > " >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5_RoCoJt8kbWvwvpPMYCDzM56qJjzrm54a=EfwesT-1fdz2A>