oslib: fix strlcat's incorrect copying
Fix unittests/oslib/strlcat.c test case failure.
oslib/strlcat.c implementation is incorrect for edge case inputs,
when (dsize-strlen(dst)-1 <= 0). The example below isn't supposed
to be copying anything, but the result is it does copy and
overruns the stack.
This commit replalces oslib/strlcat.c with the original implementation
under BSDL.
--
# uname
Linux
# cat ./test0.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "./oslib/strlcat.h"
int main(void) {
char *p, s[10] = "test";
int size = 200;
p = calloc(1, size);
memset(p, 65, size - 1);
printf("%lu %lu %s\n", sizeof(s), strlen(s), s);
strlcat(s, p, strlen(s));
printf("%lu %lu %s\n", sizeof(s), strlen(s), s);
return 0;
}
# gcc -Wall -g ./test0.c ./oslib/strlcat.c
# ./a.out
10 4 test
10 203 testAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Segmentation fault (core dumped)
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>