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] [day] [month] [year] [list]
Message-ID: <CAHp75VeHvGkPf_OHDNfB3aQ-196HHP0hddnPS6DVJsBsiBAMdg@mail.gmail.com>
Date: Sat, 2 Aug 2025 11:59:25 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: Colin Ian King <colin.i.king@...il.com>, Andy Shevchenko <andy@...nel.org>, 
	Hans de Goede <hansg@...nel.org>, Mauro Carvalho Chehab <mchehab@...nel.org>, 
	Sakari Ailus <sakari.ailus@...ux.intel.com>, 
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>, linux-media@...r.kernel.org, 
	linux-staging@...ts.linux.dev, kernel-janitors@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH][next] media: atomisp: Fix incorrect snprintf format
 specifiers for signed integers

On Sat, Aug 2, 2025 at 11:02 AM Dan Carpenter <dan.carpenter@...aro.org> wrote:
>
> On Sat, Aug 02, 2025 at 10:45:49AM +0200, Andy Shevchenko wrote:
> > On Sat, Aug 2, 2025 at 9:32 AM Dan Carpenter <dan.carpenter@...aro.org> wrote:
> > > On Fri, Aug 01, 2025 at 11:57:43PM +0200, Andy Shevchenko wrote:
> > > > On Fri, Aug 1, 2025 at 6:01 PM Colin Ian King <colin.i.king@...il.com> wrote:
> > > > >
> > > > > There are incorrect %u format specifiers being used to for signed integers,
> > > > > fix this by using %d instead.
> > > >
> > > > Both of them sound to me like the fix of the symptom and not the
> > > > cause. Can we simply make types of the iterators to be unsigned
> > > > instead?
> > >
> > > Making iterator unsigned by default only increases the rate of bugs.
> >
> > How? Please, make sure this is relevant to this case.
>
> You're suggesting that he should change:
>
> -       int i, j;
> +       unsigned int i, j;
>
> It's just bad advice.

I disagree with this statement. The code varies and in some cases it
should be negative, but those cases are not these one, or you are
talking about _this_ case? If you are talking in general, again I
fully disagree with your statement. One needs to use a common sense.

>  Making iterators unsigned makes the code less
> safe.  It leads underflow bugs when we do subtraction:
>
>         for (i = num - 1; i < limit; i++) {
>
> Now i starts at UINT_MAX.  Which I guess is fine in this example...

Depends on the num semantics. The main what one needs is a common sense.

> But it also leads to endless loops in the error handling:
>
>         while (i-- >= 0) {

How? Error handling usually takes i > 0. Bad example, try harder.

>
> Making iterators unsigned is a bad habbit

True when use in conjunction with the same statement for signed cases:
"Making iterators signed is a bad habit"

> and it's bad advice in terms
> of the data that we have with regards to bugs.

Disagree. Bugs are common because people do not understand the C
language and its integer rules, wrap-arounds, etc. I believe in many
cases using signed iterators "fix" the bugs due to other variables
also being signed instead of both being unsigned.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ