lkml.org 
[lkml]   [2021]   [Oct]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 1/1] s390: Use string_upper() instead of open coded variant
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:

...

> > + /* Segment name is limited by 8 characters + NUL */
> > + 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?

> > + string_upper(dcss_name, tmp);

...

> > static struct dcss_segment *
> > segment_by_name (char *name)
> > {
> > - 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.

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2021-10-05 10:19    [W:0.111 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site