Scott Cheloha <scottchel...@gmail.com> wrote:

> On Mon, Dec 06, 2021 at 03:09:05PM -0700, Theo de Raadt wrote:
> > +        * Use memmove(3) instead of memcpy(3), just in case key
> > +        * partially overlaps with the end of the array.
> > 
> > It isn't a "just in case", as in a possibility.
> 
> ?
> 
> > It is gauranteed this condition will happen.
> 
> I don't follow you.  I would expect this to basically never happen.
> It's user error.  We're well outside of "defined behavior" here, I'm
> just trying to make lsearch(3) do the best thing in a bad situation.

Does the specification of this function say that a caller CANNOT lay out
the objects that way?  If it doesn't, they eventually will.

> Like, I can write a program to demonstrate the problem, but this is
> not something you would ever do intentionally.

That is backwards again.  Someone else will.  By accident, even.

> +
> +     /*
> +      * Use memmove(3) to ensure the key is copied cleanly into the
> +      * array, even if the key overlaps with the end of the array.
> +      */
> +     memmove((void *)end, key, width);
>       return((void *)end);
>  }

Yes that is better, it avoids calling the situation abstract or vague.

Reply via email to