lkml.org 
[lkml]   [2023]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] kobject: Replace strlcpy with strscpy
On Mon, Jul 10, 2023 at 9:13 AM David Laight <David.Laight@aculab.com> wrote:
>
> > int len;
> >
> > - len = strlcpy(&env->buf[env->buflen], subsystem, buffer_size);
> > - if (len >= buffer_size) {
> > + len = strscpy(&env->buf[env->buflen], subsystem, buffer_size);
> > + if (len < 0) {
> > pr_warn("init_uevent_argv: buffer size of %d too small, needed %d\n",
> > buffer_size, len);
> > return -ENOMEM;
>
> The size in the error message is now wrong.

Thanks for catching this.

> It has to be said that mostly all the strings that get copied
> in the kernel are '\0' terminated - so maybe it is all moot.
> OTOH printing (at least some of) the string that didn't fit
> is a lot more useful than its length.

How about printing out strlen(subsystem) along with the entire value
of @subsystem? So that the warn reads:

pr_warn("init_uevent_argv: buffer size of %d too small for %s, needed
%d\n", buffer_size, subsystem, strlen(subsystem));

Does that seem better?

\
 
 \ /
  Last update: 2023-07-10 20:07    [W:0.052 / U:1.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site