In lsearch(3), the key is allowed to overlap with the last element in
base.  We need to memmove(3), not memcpy(3), or we could corrupt the
key in that edge case.

ok?

Index: lsearch.c
===================================================================
RCS file: /cvs/src/lib/libc/stdlib/lsearch.c,v
retrieving revision 1.5
diff -u -p -r1.5 lsearch.c
--- lsearch.c   18 Jul 2014 04:16:09 -0000      1.5
+++ lsearch.c   6 Dec 2021 15:02:51 -0000
@@ -79,6 +79,6 @@ linear_base(const void *key, const void 
         * manual.
         */
        ++*nelp;
-       memcpy((void *)end, key, width);
+       memmove((void *)end, key, width);
        return((void *)end);
 }

Reply via email to