All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@de.ibm.com>
Subject: Re: [PATCH v1 1/1] s390: Use string_upper() instead of open coded variant
Date: Tue, 5 Oct 2021 15:09:43 +0300	[thread overview]
Message-ID: <YVxAh+0SeLEgh85e@smile.fi.intel.com> (raw)
In-Reply-To: <YVwSxGyx45gs2+ZW@osiris>

On Tue, Oct 05, 2021 at 10:54:28AM +0200, Heiko Carstens wrote:
> On Tue, Oct 05, 2021 at 11:18:38AM +0300, Andy Shevchenko wrote:
> > On Mon, Oct 04, 2021 at 10:31:46PM +0200, Heiko Carstens wrote:
> > > On Fri, Oct 01, 2021 at 04:02:01PM +0300, Andy Shevchenko wrote:

...

> > > > +	char tmp[8 + 1];
> > > >  	int i;
> > > >  
> > > > -	for (i = 0; i < 8; i++) {
> > > > -		if (name[i] == '\0')
> > > > -			break;
> > > > -		dcss_name[i] = toupper(name[i]);
> > > > -	}
> > > > -	for (; i < 8; i++)
> > > > -		dcss_name[i] = ' ';
> > > > +	/*
> > > > +	 * This snprintf() call does two things:
> > > > +	 * - makes a NUL-terminated copy of the input string
> > > > +	 * - pads it with spaces
> > > > +	 */
> > > > +	snprintf(tmp, sizeof(tmp), "%s        ", name);
> > > 
> > > I can't say I like code where I have to count spaces in order to
> > > verify if the code is actually correct.
> > 
> > I understand your point, but have any idea how to make it differently
> > and not ugly at the same time?
> 
> Don't know. You could use strncopy+strlen+memset (with space
> character). After all I'm not very convinced that the resulting code
> buys us anything compared to the current variant.

Yup, so let's convert only the first part then.

...

> > > > -	char dcss_name[9];
> > > > +	char dcss_name[8];
> > > 
> > > string_upper will copy the terminating NUL-byte. By reducing the size
> > > of dcss_name to 8 bytes this will result in stack corruption.
> > 
> > Nope. Even in the original code this additional byte is left unused.
> 
> I'm talking about the new code, not the old code: If "name" points to
> a NUL terminated eight chararacter string, then the new code will use
> snprintf to copy it 1:1 to tmp, and the subsequent string_upper() will
> copy the string (upper cased) to dcss_name, now including the NUL
> terminating byte, which won't fit into dcss_name.
> Am I missing something here?

Ah, indeed, although it's rather bug in the implementation of above.
But original code has it not in use.

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2021-10-05 12:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 13:02 [PATCH v1 1/1] s390: Use string_upper() instead of open coded variant Andy Shevchenko
2021-10-04 20:31 ` Heiko Carstens
2021-10-05  8:18   ` Andy Shevchenko
2021-10-05  8:54     ` Heiko Carstens
2021-10-05 12:09       ` Andy Shevchenko [this message]
2021-10-11  8:21   ` David Laight
2021-10-11 10:09     ` Heiko Carstens
2021-10-12  8:04       ` David Laight
2021-10-12  9:12         ` Heiko Carstens
2021-10-07 18:07 ` Heiko Carstens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YVxAh+0SeLEgh85e@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=borntraeger@de.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.