lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 18 Aug 2021 23:15:46 +0300
From:   Sakari Ailus <sakari.ailus@....fi>
To:     Laurent Pinchart <laurent.pinchart@...asonboard.com>
Cc:     Krzysztof HaƂasa <khalasa@...p.pl>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        linux-media@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4] Driver for ON Semi AR0521 camera sensor

On Wed, Aug 18, 2021 at 07:48:30PM +0300, Laurent Pinchart wrote:
> > > +static const char *mhz(u32 value)
> > > +{
> > > +	static char buff[32];
> > > +
> > > +	if (value % 1000)
> > > +		sprintf(buff, "%u.%06u", value / (1000 * 1000), value % (1000 * 1000));
> > > +	else if (value % (1000 * 1000))
> > > +		sprintf(buff, "%u.%03u", value / (1000 * 1000), (value / 1000) % 1000);
> > > +	else
> > > +		sprintf(buff, "%u", value / (1000 * 1000));
> > > +	return buff;
> > 
> > Sorry, you can't do that. buff is allocated in the stack and the memory is
> > no longer available once the function returns.
> 
> It's a static char array, so it won't be allocated on the stack, but
> it's still bad practice as it's not thread-safe. Given that it's used in

Ah, yeah. I missed the static there.

> two debugging messages only, I'd hardcode the %u.06%u format in the
> callers.

Or just plain number in Hz. Both are fine though.

-- 
Sakari Ailus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ