Hello Geert: Thanks for your comments!
On Mon, Mar 30, 2015 at 9:59 AM, Geert Uytterhoeven <ge...@linux-m68k.org> wrote: > > What's the maximum length of init_name? It is "driver defined", this is why the initial patch used kasprintf, but the Maintainer preferred to avoid the memory handling. > strncpy() is _not_ guaranteed to zero-terminate the destination buffer. Good catch. I will fix this. > > There are two ways to fix this: > 1. Use strlcpy() instead of strncpy(), > 2. Explicitly set name[len-1] to 0 after the call to strncpy(). > > As we don't need the "security" feature of strncpy() that fills the remaining > part of the buffer with zeroes, I think using strlcpy() is the best solution. > >> + while (class_find_device(leds_class, NULL, name, match_name)) >> + snprintf(name, len, "%s_%d", init_name, ++i); > > This will become an infinite loop once the resulting string no longer fits in > the target buffer. Hence the loop should be terminated, and an error code > should be returned, once snprintf() returns a value >= len. > Will send a patch right away. Thanks >> + >> + return i; >> +} > > Gr{oetje,eeting}s, > > Geert > > -- > Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- > ge...@linux-m68k.org > > In personal conversations with technical people, I call myself a hacker. But > when I'm talking to journalists I just say "programmer" or something like > that. > -- Linus Torvalds -- Ricardo Ribalda -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/