[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YVtksmjj1eGqw5GY@osiris>
Date: Mon, 4 Oct 2021 22:31:46 +0200
From: Heiko Carstens <hca@...ux.ibm.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: linux-s390@...r.kernel.org, linux-kernel@...r.kernel.org,
Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ibm.com>
Subject: Re: [PATCH v1 1/1] s390: Use string_upper() instead of open coded
variant
On Fri, Oct 01, 2021 at 04:02:01PM +0300, Andy Shevchenko wrote:
> Use string_upper() from string helper module instead of open coded variant.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
> arch/s390/mm/cmm.c | 11 ++++-------
> arch/s390/mm/extmem.c | 21 ++++++++++++---------
> 2 files changed, 16 insertions(+), 16 deletions(-)
...
> static void
> dcss_mkname(char *name, char *dcss_name)
> {
> + /* 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.
> + 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.
Powered by blists - more mailing lists