path: root/os
diff options
authorTomohiro Kusumi <>2018-10-26 09:35:46 -0700
committerJens Axboe <>2018-10-26 10:24:28 -0600
commit199710f5822cf22bf76107f26993a9468f93a422 (patch)
treea2e52f94574359a37e490bfa9f32cce306e4e82a /os
parenta9d95828998ba65eff5a60df217d8d6ede6175bc (diff)
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 <> Signed-off-by: Jens Axboe <>
Diffstat (limited to 'os')
0 files changed, 0 insertions, 0 deletions