Messages in this thread | | | Date | Mon, 12 Feb 2018 18:11:37 +0100 | From | Willy Tarreau <> | Subject | Re: [PATCH V2] auxdisplay: use correct string length |
| |
On Mon, Feb 12, 2018 at 01:53:57PM +0100, Miguel Ojeda wrote: > > diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c > > index ea7869c..d288900 100644 > > --- a/drivers/auxdisplay/panel.c > > +++ b/drivers/auxdisplay/panel.c > > @@ -1506,10 +1506,10 @@ static struct logical_input *panel_bind_key(const char *name, const char *press, > > key->rise_time = 1; > > key->fall_time = 1; > > > > - strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str)); > > - strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str)); > > + strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str) - 1); > > + strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str) - 1); > > strncpy(key->u.kbd.release_str, release, > > - sizeof(key->u.kbd.release_str)); > > + sizeof(key->u.kbd.release_str) - 1); > > Are you sure about this patch? `kbd` says "strings can be non null-terminated". > > Willy, maybe those should just be memcpy()s? (unless the remaining > bytes, if any, must be 0).
For me this seems to be the result of yet another very stupid gcc warning trying to dissuade us from using well defined fonctions... it's unimaginable how gcc warnings have become stupid and irrelevant since its developers stopped using C to write it :-(
If you want to work around this wrong warning, probably that increasing the destination storage size by one and adding -1 to strncpy() would shut it up but that really becomes quite annoying to have to modify code and storage just to shut down a dumbass compiler trying to be smart.
Willy
| |